You can directly apply your background to the html
element and use background-size: cover
to assure it covers the whole area leaving no gap.
html {
background: #222 url('FreeVector-Fresh-Beer.jpg') no-repeat center center fixed;
background-size: cover;
}
Otherwise, you can make sure you declare height: 100%
on your body tag, so body takes the full height of the browser too and apply the background there instead.
body {
background: #222 url('FreeVector-Fresh-Beer.jpg') no-repeat center center fixed;
background-size: cover;
height: 100%;
}
Background-size: cover
assures that the whole will be covered without expanding or stretching your image; naturally that means parts of your image will be hidden. However, if you want to simply expand it, that is, stretch it, to take the full area, you may use background-size: 100% 100%
.
In general you want to use cover
and you may decide what area remains visible through background-position
(which is center, center) on my answer in the shorthand property (so you always would see the center, vertically and horizontally) but it could be:
- Horizontally: left | right | center
- Vertically: top | bottom | center