Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

CSS Background-attachment: fixed;

I am trying to add a selfmade background image to the website that I'm designing. I want the text to scroll over the background image, which it does very well if I use the "background-attachment: fixed;" property, however this means that the size of the image is change and I cannot seem to find a way to change the size back.

Here is my CSS:

.page-info {
    min-height: calc(100vh - 158.89px);
    background: url('../img/FINAL Smithdiagram.png');
    background-repeat: no-repeat;
    background-attachment: fixed;
}

Does anyone have any idea of how I can reduce the size of the background image whilst keeping the effect of scrolling text on top with "background-attachment: fixed;"?

Yes, thank you so much, Luke! I actually noticed that I was messing around with the wrong media query which ultimately made things harder.

All good now!

1 Answer

You can use the background-size property to adjust the size of the background image. Depending on your image, the context of how it is used, and the content on the page, it can be really difficult to know exactly what the best way to implement it is. Sometimes it usually takes a bit of trial and error. CSS Tricks has an excellent article on that topic here: https://css-tricks.com/perfect-full-page-background-image/ .