I would like to alternate list-style-type properties for ul lists, so that the outer is a disc, then one inner ul list is a circle, than one more inner is a disc, and so on.
Essentially, what I want is this:
<ul><!-- use disc -->
<li>Lorem ipsum</li>
<li>
<ul><!-- use circle -->
<li>Lorem ipsum</li>
<li>
<ul><!-- use disc -->
<li>Lorem ipsum</li>
</ul>
</li>
<li>Lorem ipsum</li>
</ul>
</li>
<li>Lorem ipsum</li>
</ul>
How would I accomplish this using CSS?
While you can use a :before pseudo-selector to add a "-" or "•" character in front of your element, it doesn't really make your element behave like a bullet point. Your element may look like a bullet point, but that's just a dirty hack, really, and should be avoided!
Making CSS Remove Bullets It is possible to remove bullets from ul lists by setting the CSS list-style-type property to none . As a result, the bullets disappear from the list. Note: to get rid of the automatic indentation, you can also set margin and padding to 0.
Like this...
li { list-style: circle; }
li li { list-style: disc; }
li li li { list-style: square; }
And so on...
The first level of list items will have the "circle" type marker. The second (embedded) will use "discs". The third level will use squares.
Simply take the above CSS and change the list-style
to suit your needs. You can find a list of list-style
types here: http://www.w3schools.com/cssref/pr_list-style-type.asp
You could use separate styles by adding class
or id
to the ul
tags:
<ul class="disk"><!-- use disk -->
<li>Lorem ipsum</li>
<li>
<ul class="circle"><!-- use circle -->
<li>Lorem ipsum</li>
<li>
<ul class="disk"><!-- use disk -->
<li>Lorem ipsum</li>
</ul>
</li>
</ul>
</li>
</ul>
.disk
{
list-style-type: disc;
}
.circle
{
list-style-type: circle;
}
Or you could add styles to ul
s depending on how they are nested:
ul
{
list-style-type:disc;
}
ul li ul
{
list-style-type:circle;
}
ul li ul li ul
{
list-style-type:disc;
}
Off the top of my head, so there might be some minor errors, but both these examples should basically work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With