Background Gradient 100% body CSS

I need a body background that used the whole viewport. Time ago I used to see solutions like html{ height: 100%;} or set in the body.

None of these worked for me in my different scenarios when using a background gradient.

Solution: fixed

Adding fixed at the background gradient style fixes everything everywhere. Weather the page is short (smaller than the browser window), long pages, iPad, iPhone...

Here's a background gradient example with the fixed attribute.

body {
    background: #00acc1;
    background: -moz-linear-gradient(-45deg, #00acc1 0%, #24678d 44%, #24678d 100%) fixed;
    background: -webkit-linear-gradient(-45deg, #00acc1 0%,#24678d 44%,#24678d 100%) fixed;
    background: linear-gradient(135deg, #00acc1 0%,#24678d 44%,#24678d 100%) fixed;
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00acc1', endColorstr='#24678d',GradientType=1 );
}Code language: CSS (css)

Demo

View Demo

Leave a Reply

Your email address will not be published. Required fields are marked *