Soulevoker
Soulevoker

Reputation: 163

CSS Gradients stopping then repeating

I want to make my background on my site a gradient. This is because I am just starting out making sites, and I just want to learn how CSS works and what not.

Here is my code:

background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* FF3.6+ */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(0, 0, 0, 0)), color-stop(100%, rgba(0, 0, 0, 0.65))); /* Chrome,Safari4+ */
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, .8) 0%, rgba(0, 0, 0, 0.65) 100%); /* Chrome10+,Safari5.1+ */
background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* Opera 11.10+ */
background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* IE10+ */
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#a6000000',GradientType=0 ); /* IE6-9 */

I do NOT want the gradient to stop then repeat from white. I want the gradient to change depending on the current media's size.

Upvotes: 1

Views: 2295

Answers (2)

Rayshawn
Rayshawn

Reputation: 2617

This is what you need to do, apply height:100% to html and body. If your site will be on mobile devices you will need to add

background-attachment: fixed to the body as well.

  html{
 height: 100%;
 }
 body{
 height: 100%;
 background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0) 100%, rgba(0, 0, 0, 0.65) 100%); /* FF3.6+ */
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(100%, rgba(0, 0, 0, 0)), color-stop(100%, rgba(0, 0, 0, 0.65))); /* Chrome,Safari4+ */
 background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, .8) 0%, rgba(0, 0, 0, 0.65) 100%); /* Chrome10+,Safari5.1+ */
  background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0) 100%, rgba(0, 0, 0, 0.65) 100%); /* Opera 11.10+ */
 background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0) 100%, rgba(0, 0, 0, 0.65) 100%); /* IE10+ */
 background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.65) 100%); /* W3C */
 filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00000000', endColorstr='#a6000000',GradientType=0 ); /* IE6-9 */}

Upvotes: 0

bookcasey
bookcasey

Reputation: 40473

Set height and width of html and body to 100%, and these options for the background:

background-repeat: no-repeat;
background-attachment: fixed;

Demo

If you don't the gradient will repeat when your scroll past the height of the browser.

Upvotes: 2

Related Questions