Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css difference between background: and background-image:

Tags:

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.

like image 306
epicT Avatar asked Sep 21 '16 05:09

epicT


People also ask

What is the difference between background and background image in CSS?

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.

What is the basic difference between background color and background image?

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.

What is CSS background image?

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?

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.


2 Answers

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; 
like image 166
danish farhaj Avatar answered Sep 27 '22 23:09

danish farhaj


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; 
like image 35
quik_silv Avatar answered Sep 28 '22 00:09

quik_silv