Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add background image to <ol> numbers

Tags:

css

I can't figure out an elegant way to accomplish the following using CSS:

screenshot

I need the numbers of the ordered list to have the teal bubble-looking background. I have this image (which includes the white stroke):

bubble

But I can't figure out how to put it behind each of the numbers using CSS. Thanks.

like image 308
robertwbradford Avatar asked Jun 26 '11 01:06

robertwbradford


2 Answers

I would probably do something like this:

ol {
    list-style-position: inside;
    color: white;
}
ol li {

    background-image: url('nswCH.png');
    background-position: -5px;
    background-repeat: no-repeat;
    padding-left: 7px;
}
like image 105
eagle12 Avatar answered Oct 04 '22 14:10

eagle12


I would prefer in following way

 /* reset the ol counter with class liststyled*/
ol.liststyled {
counter-reset: item;
list-style-type: none;
list-style-position: inside;
padding-left: 0;
}
/* make the li relative */
ol.liststyled li{
position: relative;   
padding-left: 35px;
}
/*add absolute positioned img element background to our relative li */
ol.liststyled li:before{
font-size: .8em;
line-height: 25px;
vertical-align: middle;
width: 25px;
color: #fff;
text-align: center;
height: 25px;
content: counter(item) "  "; 
counter-increment: item ;
position: absolute;
left: 0;
background: url('../img/bulletolback.png') center no-repeat;
}
like image 23
Suman Avatar answered Oct 04 '22 16:10

Suman