Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use CSS to make background-image above background-color in a list

This is the code

<ul>
    <li class="test">
         <a href="#">
            <h2>Blah</h2>
            <p>Blah Blah Blah</p>
         </a>
    </li>
</ul>

Basically, my list already has some styling, for example, I set the background-color for it.

Now in the class "test", I also set a background-image.

My question is I want to make the background-image stays above the background-color and I dont know how to achieve this. I tried with z-index but I think it is not applicable for background-image.

Please take a look at the image

Output

Edit: This is the CSS Code

For example, this is the styling for my list

#sidebar ul li{  
    background:#ccf;
}

And this is the styling for the class test

.test{
    background-image: url('img/big_tick.png');
    background-repeat:no-repeat;
    background-position: bottom right;
    -moz-background-size: 30%;
    -webkit-background-size: 30%;
    background-size: 30%;    
    margin-right: 30px;
}
like image 932
user826224 Avatar asked Dec 13 '11 15:12

user826224


People also ask

How do I overlay the background color of an image in CSS?

The most common implementation for these overlays is to introduce an extra div , stretched to cover the element with the background image. The new div has no content, but is given a background-color and set to a lower opacity , allowing the background image to partially show through.

Can we use background image and background color together in CSS?

It allows you combining background-color , background-image , background-position and background-repeat properties.

How we can add background Colour and image to the screen?

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.

How do you add two background colors in CSS?

CSS allows you to add multiple background images for an element, through the background-image property. The different background images are separated by commas, and the images are stacked on top of each other, where the first image is closest to the viewer.


1 Answers

Add the !important attribute to your background-image. Like this:

.test a{
background-image: url('img/big_tick.png') !important;
background-repeat:no-repeat;
background-position: bottom right;
-moz-background-size: 30%;
-webkit-background-size: 30%;
background-size: 30%;    
margin-right: 30px;

}

I have an example fiddle here

EDIT: I changed the class to .test a to reflect the actual styling scheme

like image 106
piebie Avatar answered Oct 16 '22 14:10

piebie