Welcome to the Treehouse Community
Looking to learn something new?
Why set background to no-repeat when the image is not going to repeat anyway?
In Guil's Bootstrap Deep Dive, we set the background image to repeat on a couple of instances. I was playing around and I noticed not doing this had zero effect on the look of the site. I am assuming the image was too big for the container to repeat anyway. Is there a benefit to doing this that I am not seeing?
The initial value for
repeat. Not having been through this deep dive I can only guess that Guil wanted to set it explicitly for the purposes of teaching but in practice you would probably leave it off if you wanted the background to repeat because that's the default. The other reason you might need to set it to
repeat is if it was set to something else higher up in the css file and you needed to get it back to
As you mentioned, if the background image is too big to fit into it's container then using
no-repeat will have no visual difference on the page. Actually, depending on the background-position property you could see a big image partially repeating.
It's just clean. If you review your code to another time you don't have to look at your page to see that the background won't or will repeat. You should set it everytime because every browser got other default settings.
- Sorry for my English, I'm German. :)
Thanks guys for the help! Jason Anello -- I think that is exactly what we are doing in a couple of places -- with background positioning, moving the large image out of the "viewport" and therefore making the "no-repeat" relevant. I didnt think about that until you said that. Thanks again!