I am wondering if it's possible to utilize font-awesome (or any other iconic font) classes to create a custom <li>
list-style-type?
I am currently using jQuery to do this, ie:
$("li.myClass").prepend("<i class=\"icon-chevron-right\"></i>");
However, this doesn't style properly when the <li>
text wraps across the page as it considers the icon to be part of the text, not the actual bullet-indicator.
Any tips?
I did it like this:
Or you can try this if you want to change the color:
As per the Font Awesome Documentation:
Or, using Jade:
The CSS Lists and Counters Module Level 3 introduces the
::marker
pseudo-element. From what I've understood it would allow such a thing. Unfortunately, no browser seems to support it.What you can do is add some padding to the parent
ul
and pull the icon into that padding:Adjust the padding/font-size/etc to your liking, and that's it. Here's the usual fiddle: http://jsfiddle.net/joplomacedo/a8GxZ/
=====
This works with any type of iconic font. FontAwesome, however, provides their own way to deal with this 'problem'. Check out Darrrrrren's answer below for more details.
I'd like to provide an alternate, easier solution that is specific to FontAwesome. If you're using a different iconic font, JOPLOmacedo's answer is still perfectly fine for use.
FontAwesome now handles list styles internally with CSS classes.
Here's the official example:
I wanted to add to JOPLOmacedo's answer. His solution is my favourite, but I always had problem with indentation when the li had more than one line. It was fiddly to find the correct indentation with margins etc. But this might concern only me.
For me absolute positioning of the :before pseudo-element works best. I set padding-left on ul, negative position left on the :before element, same as ul's padding-left. To get the distance of the content from the :before element right I just set the padding-left on the li. Of course the li has to have position relative. For example
Hopefully this is clear and has some value for someone else than me.