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.

Aching back from coding all day?

Acupressure Mat & Pillow

Aching back from coding all day? Try Back Problems

Relieve your stress, back, neck and sciatic pain through 1,782 acupuncture points for immediate neck pain relief. Made for lower, upper and mid chronic back pain treatment, and improves circulation, sleep, digestion and quality of life.

$$ Check price
144.87144.87Amazon 4.5 logo(1,890+ reviews)

More Back Problems resources

Build modern and responsive webpages


Build modern and responsive webpages Try Front-end

This book teaches HTML as if it's for anyone - hobbyists, students, and professionals - and it's full-color throughout. It utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging. You can progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure.

$ Check price
29.9929.99Amazon 4.5 logo(926+ reviews)

More Front-end resources