HTML list with different bullet images

I know that you can install an image instead of the default HTML templates:

list-style-image: url(...);

But I did not find a way in which I can set different images in the same list. eG: Instead of the first bullet, img_1 is displayed instead of the next 5 bullets img_2 ....

+4
source share
5 answers

HTML

<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>

CSS (not working on IE 7.8) -

ul li:nth-child(1){
list-style-image:url('image1.png');
}
ul li:nth-child(2){
list-style-image:url('image2.png');
}
ul li:nth-child(3){
list-style-image:url('image3.png');
}

CSS for all browsers including IE 7.8

ul li:first-child{
list-style-image:url('image1.png');
}
ul li:first-child + li{
list-style-image:url('image2.png');
}
ul li:first-child + li + li{
list-style-image:url('image3.png');
}
ul li:first-child + li + li + li{
list-style-image:url('image4.png');
}
+4
source

You need to use nth-childProperty

CSS

li:nth-child(1){list-style-image:url(image)}

Here is the demo http://jsfiddle.net/5VB2u/

+2
source

LI

<ul class="navlist">
    <li class="img_1">element1</li>
    <li class="img_2">element2</li>
</ul>
<style>
.navlist li.img_1
{
padding-left: 10px;
background-image: url(images/image1.gif);
background-repeat: no-repeat;
background-position: 0 .5em;
}
.navlist li.img_2
{
padding-left: 10px;
background-image: url(images/image2.gif);
background-repeat: no-repeat;
background-position: 0 .5em;
}
</style>
+2

,

<li class="first"></li>
<li class="second"></li>
...

li.first {
  ⋮ declarations
}

li.second {
  ⋮ declarations
}
...

nth-child

li:nth-child(1) {
  ⋮ declarations
}

li:nth-child(2) {
  ⋮ declarations
}
...
+1

you should / can use classes in your list items:

<ul>
  <li class="bar>
   <a href="#" title="foo">Foo</a>
  </li>
  <li class="foo>
   <a href="#" title="bar">Bar</a>
  </li>
</ul>

CSS for bullet images for <li>

ul {
  list-style: none;
}
li {
 padding-left: 25px; /*adjust to your needs*/
}
li.bar {
  background: url(img_2.png) no-repeat 0 50%;
}
li.foo {
  background: url(img_1.png) no-repeat 0 50%;
}

CSS for bullet images for <a>

ul {
  list-style: none;
}
li a {
 padding-left: 25px; /*adjust to your needs*/
 display: block;
}
li.bar a {
  background: url(img_2.png) no-repeat 0 50%;
}
li.foo a {
  background: url(img_1.png) no-repeat 0 50%;
}
+1
source

All Articles