Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put an icon after list item with :after and font awesome

Tags:

I am having a problem getting the icon to appear directly after a list item in a <ul> using font awesome and :after.

The <li> with the active class should have the icon after it but when another <ul> is added in before closing the list item, it's puts the icon after the entire secondary list.

<div id="thirdLevMenu"> <ul> <li class="active">Integrated Coastal Watershed Management Plans <ul> <li><a href="http://design-irwmp3.migcom.com/app_pages/view/7931">Russian River Integrated Coastal Watershed Management Plan</a></li> <li><a href="http://design-irwmp3.migcom.com/app_pages/edit/http:/www.goldridgercd.com/watersheds/salmoncreekplan.html" target="_blank">Salmon Creek Coastal Watershed Management Plan</a></li> <li><a href="http://design-irwmp3.migcom.com/app_pages/edit/http:/www.mattole.org/plan" target="_blank">Mattole Coastal Watershed Management Plan</a></li> <li><a href="http://design-irwmp3.migcom.com/app_pages/edit/http:/www.trinidad.ca.gov/documents-library/category/30-icwmp.html" target="_blank">Trinidad-Westhaven Coastal Watershed Management Plan</a></li> </ul> </li> </ul> </div> 

I can't for the life of me figure out what I am doing wrong.

Here's my jsfiddle

like image 983
tyler_lisa Avatar asked Sep 13 '13 19:09

tyler_lisa


People also ask

How do I add the Font Awesome icon in after before elements?

You just have to add the following CSS to your after or before element: font: normal normal normal 14px/1 FontAwesome; content: '\f042'; Here the content is the icon you want to add. Just copy the Unicode of the icon from the FA website and paste it in the content with a \ prefix.

How do I add Font Awesome icon inside input field?

The font-awesome icon can be placed by using the fa prefix before the icon's name. Example: In this example, we will take a form where the input field is necessary. After that, we will place the font-awesome icon inside the input field. We will use the CDN link to use the font-awesome icons.

How do I add an icon to an element list?

To insert an icon, add the name of the icon class to any inline HTML element. The <i> and <span> elements are widely used to add icons. All the icons in the icon libraries below, are scalable vector icons that can be customized with CSS (size, color, shadow, etc.)


1 Answers

As I mentioned in the comment:

"When you add that second <ul> inside the top <li>, that entire inside list becomes part of the parent list item. It's doing exactly what you're telling it too, it's putting the arrow directly after the <li>."

If you want the icon to go after the text reading "Integrated Coastal Watershed Management Plans" instead, add a span around that title and tweak your CSS to add the :after pseudo element to that span instead of the entire <li>.

HTML

<li class="active">  <span class = "title">Integrated Coastal Watershed Management Plans</span>   ... </li> 

CSS

#thirdLevMenu ul li.active .title:after{     content: '\f0da';    font-family: FontAwesome;    font-weight: normal;    font-style: normal;    margin:0px 0px 0px 10px;    text-decoration:none;  }  

Here's an updated fiddle.

like image 119
Jason Avatar answered Sep 22 '22 15:09

Jason