Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set two background images on the same element with CSS?

Tags:

html

css

Sample HTML code:

<table>
<tr>
 <td class="a b">

Sample CSS file:

.a
{
  background-image:url(a.png);
}

.b
{
  background-image:url(b.png);
}

It seems like the "b" part is ignored.

Is there any way to inlclude both images in the same cell, even using other technique?

like image 208
pvieira Avatar asked May 18 '09 23:05

pvieira


People also ask

Can we put two background images HTML?

The multiple background images for an element can be put in the HTML page using CSS. Use CSS background property to add multiple background images for an element in any pattern and use other CSS property to set the height and width of the images.

What CSS property sets one or more background images on an element?

The background-image CSS property sets one or more background images on an element.

What will happen if we use CSS to set both a background image and a background color for the same element?

Answer. When we have both a background-color and background-image property applied to the same element, whichever property that is physically lower in the CSS file will be applied.

How do I put two background colors in HTML?

To add background color in HTML, use the CSS background-color property. Set it to the color name or code you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a table, heading, div, or span tag.


3 Answers

Now you can do with CSS3. http://www.zenelements.com/blog/css3-background-images/

#my_CSS3_id {
background: url(image_1.extention) top left no-repeat,
url(image_2.extention) bottom left no-repeat,
url(image_3.extention) bottom right no-repeat;
}
like image 148
Jitendra Vyas Avatar answered Sep 30 '22 02:09

Jitendra Vyas


You could do this:

<td class="a"><div class="b">...</div></td>

Then the td will have the first background, and the div inside it will have the second. If one is transparent, the other will show through. I think b.png will be on top, but I'm not sure about that.

like image 32
Samir Talwar Avatar answered Sep 30 '22 04:09

Samir Talwar


It's an intriguing idea, but think about how other properties work, such as color.

.a { color: red; }
.b { color: blue; }

How could the text be both red and blue? In this case, blue wins the tiebreaker, because it's specified later.

There may be another way, if you can create an image ab.png that is the result of combining of a.png and b.png.

.a { background-image(a.png) }
.b { background-image(b.png) }
.a.b { background-image(ab.png) }

Caveat: It doesn't work in IE6.

like image 29
Patrick McElhaney Avatar answered Sep 30 '22 02:09

Patrick McElhaney