You're going to need fixed-width icons to accomplish what you're asking. There's no way of aligning the items unless there is a fixed-width. You can add a fixed-width to font-awesome icons with the class icon-fixed-width
since version 3.1.1, and fa-fw
since version 4.0. That gives a fixed with of 1.28571429em
, which is annoying, but consistent.
Unfortunately CSS has no :parent
selector, so you'll probably need to add a class to the <li>
tags specifying whether of not they have an icon contained within:
<ul>
<li class="yes"><i class="fa fa-fw fa-chevron-down"></i>Item 1</li>
<li class="yes"><i class="fa fa-fw fa-chevron-left"></i>Item 2</li>
<li>Item 3</li>
</ul>
li:not(.yes) {
padding-left: 1.28571429em;
}
I've created a fiddle of this here: http://jsfiddle.net/3qwkkg4a/1/
Of course, you could always put the class on the <li>
tags that don't contain the icons, or just target the third one with li:nth-of-type(3)
for this particular example ;)
Hope this helps! :)
EDIT
These classes can also be added through jQuery, assuming you have access, using:
$('li:has(i)').addClass('yes');
A fiddle showcasing this can be seen here, leaving the HTML untouched:
http://jsfiddle.net/Obsidian_Age/3qwkkg4a/2/