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

The Modern Web

Build modern and responsive webpages Try Front-end

The Modern Web will guide you through the most important tools of device-agnostic web development, including HTML5, CSS3, and JavaScript. The plain-english explanations and practical examples emphasize the techniques, principles, and practices that you'll need to easily transcend individual browser quirks and stay relevant as these technologies are updated.

$ Check price
34.9534.95Amazon 4.5 logo(30+ reviews)

More Front-end resources

Aching back from coding all day?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources