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

Responsive Typography

Build modern and responsive webpages Try Front-end

Responsive web design helps your site maintain its design integrity on a variety of screen sizes, but how does it affect your typography? With this practical book, graphic designers, web designers, and front-end developers alike will learn the nuts and bolts of how to get the best appearance from type without sacrificing performance on any device.

$ Check price
24.9924.99Amazon 4.5 logo(3+ reviews)

More Front-end resources

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources