Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize list item bullets using CSS

Is it possible to change the size of an <li> element's bullet?

Take a look at the code below:

li {
    list-style: square; /* I want to change the size of this squared bullet. */
}

I can't seem to find any way to achieve that.

like image 977
Alex Avatar asked Jun 23 '11 15:06

Alex


People also ask

How do I create a custom bullet in CSS?

Creating a marker #The ::marker pseudo-element marker box is automatically generated inside every list item element, preceding the actual contents and the ::before pseudo-element.

How do I change the shape of a bullet in CSS?

Changing Bullet Point Shape button at the bottom of the Classic Builder. On line 3, you can change the bullet point shape by replacing square with another value, such as disc or circle. For more about bullet point shapes, check out W3 School's CSS list-style-type Property. Save and Publish, or Republish the page.


4 Answers

You mean altering the size of the bullet, I assume? I believe this is tied to the font-size of the li tag. Thus, you can blow up the font-size for the LI, then reduce it for an element contained inside. Kind of sucks to add the extra markup - but something like:

li {font-size:omgHuge;} li span {font-size:mehNormal;} 

Alternately, you can specify an image file for your list bullets, that could be as big as you want:

ul{   list-style: square url("38specialPlusP.gif");  } 

See: http://www.w3schools.com/css/css_list.asp

like image 117
adc Avatar answered Oct 11 '22 15:10

adc


Based on @dzimney answer and similar to @Crisman answer (but different)

That answer is good but has indention problem (bullets appear inside of li scope). Probably you don't want this. See simple example list below (this is a default HTML list):

  • Lorem ipsum dolor sit amet, ei cum offendit partiendo iudicabit. At mei quaestio honestatis, duo dicit affert persecuti ei. Etiam nusquam cu his, nec alterum posidonium philosophia te. Nec an purto iudicabit, no vix quod clita expetendis.

  • Quem suscipiantur no eos, sed impedit explicari ea, falli inermis comprehensam est in. Vide dicunt ancillae cum te, habeo delenit deserunt mei in. Tale sint ex his, ipsum essent appellantur et cum.

But if you use the mentioned answer the list will be like below (ignoring the size of the bullets):

Lorem ipsum dolor sit amet, ei cum offendit partiendo iudicabit. At mei quaestio honestatis, duo dicit affert persecuti ei. Etiam nusquam cu his, nec alterum posidonium philosophia te. Nec an purto iudicabit, no vix quod clita expetendis.

Quem suscipiantur no eos, sed impedit explicari ea, falli inermis comprehensam est in. Vide dicunt ancillae cum te, habeo delenit deserunt mei in. Tale sint ex his, ipsum essent appellantur et cum.


So I recommend this approach that resolves the issue:

li {     list-style-type: none;     position: relative;    /* It's needed for setting position to absolute in the next rule. */ }  li::before {     content: '■';     position: absolute;     left: -0.8em;          /* Adjust this value so that it appears where you want. */     font-size: 1.1em;      /* Adjust this value so that it appears what size you want. */ }
<ul>     <li>Lorem ipsum dolor sit amet, ei cum offendit partiendo iudicabit. At mei quaestio honestatis, duo dicit affert persecuti ei. Etiam nusquam cu his, nec alterum posidonium philosophia te. Nec an purto iudicabit, no vix quod clita expetendis.</li>     <li>Quem suscipiantur no eos, sed impedit explicari ea, falli inermis comprehensam est in. Vide dicunt ancillae cum te, habeo delenit deserunt mei in. Tale sint ex his, ipsum essent appellantur et cum.</li> </ul>
like image 29
Mir-Ismaili Avatar answered Oct 11 '22 16:10

Mir-Ismaili


You can wrap the contents of the li in another element such as a span. Then, give the li a larger font-size, and set a normal font-size back on the span:

http://jsfiddle.net/RZr2r/

li {
    font-size: 36px;
}
li span {
    font-size: 18px;
}
<ul>
    <li><span>Item 1</span></li>
    <li><span>Item 2</span></li>
    <li><span>Item 3</span></li>
</ul>
like image 36
thirtydot Avatar answered Oct 11 '22 16:10

thirtydot


Depending on the level of IE support needed, you could also use the :before selector with the bullet style set as the content property.

li {  
  list-style-type: none;
  font-size: small;
}

li:before {
  content: '\2022';
  font-size: x-large;
}

You may have to look up the HTML ASCII for the bullet style you want and use a converter for CSS Hex value.

like image 28
dzimney Avatar answered Oct 11 '22 16:10

dzimney