3

I would like to have a gradient background fill the entire page/body. Here's what I've tried. It works, but after scrolling it doesn't stretch to the full height of the page.

body {
    width: 100%;
    height: 100%;
    background: #034b52 url(../../themes/images/bg.jpg) no-repeat center fixed;
    color: #fff;
}

body:after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: linear-gradient(to bottom, rgba(3, 75, 82, 1) 0%, rgba(3, 75, 82, 0) 100%);
    content: '';
    z-index: -1;
}
thepio
  • 6,193
  • 5
  • 35
  • 54
Stack Over
  • 37
  • 1
  • 6
  • http://stackoverflow.com/questions/18094134/fixed-gradient-background-with-css use background-attachment: fixed ; on body tag and apply background to body tag – abhirathore2006 Sep 05 '16 at 10:13

3 Answers3

13

Apply the following CSS:

body {
     background: linear-gradient(to bottom, rgba(3,75, 82, 1) 0%, rgba(3,75, 82, 0) 100%);
    height: 100%;
    margin: 0;
    background-repeat: no-repeat;
    background-attachment: fixed;
}
Anuj
  • 306
  • 2
  • 9
0

Add this one

background-attachment: fixed;

The background-attachment property sets whether a background image scrolls with the rest of the page, or is fixed. There are three values: scroll, fixed, and local.

aswzen
  • 1,512
  • 29
  • 46
-2

Try this

body{
  background: url("https://upload.wikimedia.org/wikipedia/commons/f/f0/Googlelogo1997.jpg") no-repeat center center, linear-gradient(green, blue);
height:100%;
 
}
html{height:100%;}
<body>
here we go
</body>