04. Positioning A Background

To position a background within the containing element, we use the background-position property.

The values we can place are top, center, bottom, left, and right.

Additionally, we can use combintations like right top, which is exemplified here.

We can also use a length or a percentage. The point of origin is the top left, which can be specified by 0% 0%. 50% 50% would be center.

Attaching the Background with fixed

Sometimes you want the background to stay in place while the user scrolls down. In this case, all other elements will move down, while the background stays in place.

To achieve this effect, use the background-attachment property with the fixed value.

Alternatively, you can specify scroll if you want the background image to move up and down as the user scrolls.

Make sure your image is long enough, or is repeatable if you set your value to scroll!

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed interdum vitae metus in placerat. Fusce vel tellus bibendum, scelerisque diam a, suscipit arcu. Vestibulum id purus vitae tortor consequat tempor in nec quam. Sed quis augue quis urna elementum semper. Pellentesque eleifend accumsan tempor. Donec efficitur, dui ut convallis vulputate, tortor velit placerat odio, et molestie urna arcu in felis. Proin ultricies purus ullamcorper, condimentum dolor at, ornare elit. Ut et mi nec massa euismod iaculis. Nullam ullamcorper, dolor nec ultrices elementum, tellus lorem tempor metus, id porta ligula massa et nisi. Sed hendrerit orci a turpis efficitur, et mollis felis imperdiet. Donec viverra ultrices viverra. Vestibulum a mi nec massa elementum tristique in vitae magna. Ut non ipsum quis eros sollicitudin mattis a id justo. Sed eu suscipit tellus, nec sollicitudin sapien.

Quisque quis enim fermentum, consectetur metus vitae, varius leo. Maecenas feugiat, metus vitae semper vehicula, nisl dui pellentesque purus, vitae auctor lorem nibh quis metus. Nullam ac mattis massa. Fusce ultricies dapibus nulla, sodales pellentesque arcu molestie in. Donec eget leo vel tellus convallis porttitor. Maecenas lorem nisi, fermentum auctor scelerisque id, placerat eget magna. Duis finibus nec dolor quis elementum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent suscipit pellentesque tortor, non egestas mi tempor sed. Ut laoreet aliquam nisi vel rutrum. Suspendisse volutpat et arcu vel varius. Nulla facilisi. Ut in nisi justo. Morbi at congue dui, in euismod sem.

Sed vestibulum nisi eget semper accumsan. Mauris in nunc eu metus pellentesque blandit vitae pretium magna. Donec quis est pellentesque, rhoncus sapien id, fermentum nunc. Etiam sed imperdiet nibh. Mauris sed est in ipsum interdum semper. Vestibulum et faucibus odio. Aliquam pulvinar, dui eu rhoncus sodales, tellus lorem aliquet leo, sed pellentesque tellus tellus ut diam. Sed sit amet orci nunc. Donec nec justo eu lorem fringilla molestie at eget ex. Phasellus aliquet ipsum vitae arcu mattis, eu tempor nulla finibus. Ut euismod, ipsum eget rhoncus porttitor, mauris nulla ultrices nisi, quis venenatis ipsum metus sed ante. Donec pulvinar nisl in faucibus porttitor. Cras in orci mauris.

Build modern and responsive webpages

JavaScript & JQuery

Build modern and responsive webpages Try Front-end

This book was written for anyone who wants to use JavaScript to make their websites a little more interesting, engaging, interactive, or usable. In particular, it is aimed at people who do not have a degree in computer science (well, not yet anyway).

$ Check price
39.9939.99Amazon 4.5 logo(385+ reviews)

More Front-end resources

Aching back from coding all day?

Foam Seat Cushion

Aching back from coding all day? Try Back Problems

This foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.

$ Check price
99.9599.95Amazon 4.5 logo(9,445+ reviews)

More Back Problems resources