Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a Glyphicon as an LI bullet point (Bootstrap 3)

How can I change the bullet points in an HTML list and use the glyphicons that come with Bootstrap 3?

So that:

<ul>     <li>...</li>     <li>...</li> </ul> 

Displays as:

 [icon]  Facere possimus, omnis voluptas assumenda est, numquam eius modi          omnis dolor repellendus. Non numquam eius modi numam dolor omnis           tempora incidunt ut labore.   [icon]  Facere possimus, omnis voluptas assumenda est, numquam eius modi          omnis dolor repellendus. Non numquam eius modi numam dolor omnis           tempora incidunt ut labore. 

I would prefer not to have to inject extra HTML such as this...

<ul>     <li><i class="glyphicon glyphicon-chevron-right"></i> ...</li>     <li><i class="glyphicon glyphicon-chevron-right"></i> ...</li> </ul> 
like image 870
Simon East Avatar asked Jul 03 '15 01:07

Simon East


People also ask

What is bootstrap Glyphicon?

What are Glyphicons? Glyphicons are icon fonts which you can use in your web projects. Glyphicons Halflings are not free and require licensing, however their creator has made them available for Bootstrap projects free of cost.

How do I add Glyphicons in bootstrap 3?

Bootstrap 3 Glyphicons are actually fonts, so you can scale them and color them as you please. Bootstrap previously used image sprites for icons. To add a glyphicon, add a <span> tag with Bootstrap's . glyphicon class and also the class for the specific glyphicon that you require.


2 Answers

This isn't too difficult with a little CSS, and is much better than using an image for the bullet since you can scale it and colour it and it will keep sharp at all resolutions.

  1. Find the character code of the glyphicon by opening the Bootstrap docs and inspecting the character you want to use.

    Inspecting a glyphicon

  2. Use that character code in the following CSS

    li {     display: block; }  li:before {     /*Using a Bootstrap glyphicon as the bullet point*/     content: "\e080";     font-family: 'Glyphicons Halflings';     font-size: 9px;     float: left;     margin-top: 4px;     margin-left: -17px;     color: #CCCCCC; } 

    You may like to tweak the colour and margins to suit your font size and taste.

View Demo & Code

like image 77
Simon East Avatar answered Nov 04 '22 19:11

Simon East


If anyone is coming here looking to do this with Font Awesome Icons (like I was) view here: https://fontawesome.com/how-to-use/on-the-web/styling/icons-in-a-list

<ul class="fa-ul">   <li><i class="fa-li fa fa-check-square"></i>List icons</li>   <li><i class="fa-li fa fa-check-square"></i>can be used</li>   <li><i class="fa-li fa fa-spinner fa-spin"></i>as bullets</li>   <li><i class="fa-li fa fa-square"></i>in lists</li> </ul> 

The fa-ul and fa-li classes easily replace default bullets in unordered lists.

like image 45
FastTrack Avatar answered Nov 04 '22 19:11

FastTrack