quick simple question In the following example of an external CSS page;
body { background-image: url(background.jpg); } header { background: url(background.jpg); }
I understand they are effecting different element selectors, my question is what is the difference between using background vs background-image? Does one have access to specific attributes to the other? Please and thank you.
In a background property you can add background-color , repeat , no-repeat and other image attributes, but in the background-image property you are only allowed to add image. Show activity on this post. By using background, you need to specify other argument to set the background of the page.
The background-color property in CSS is used to specify the background color of an element. On the other hand, if you only use “Background:” Property, you can either specify it's valued as an image URL or as a color code or specify the value of each background property in the below-given order.
The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element.
What will happen if we use CSS to set both a background image and a background color for the same element? The background image will show with a border around it in the background color. The background image and the background color will be blended and both will show.
In a background property you can add background-color
, repeat
, no-repeat
and other image attributes, but in the background-image
property you are only allowed to add image.
background-image: url("img_tree.png"); background-repeat: no-repeat; background-position: right top; background-attachment: fixed;
and in background property you can do in one line all these
background: #ccc url(paper.gif) no-repeat;
By using background, you need to specify other argument to set the background of the page. If you just used background-image, it will only need a single argument.
background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With