Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display icon with text in html with the help of css?

Tags:

html

css

Dear All,

I want to display icon image with text in sidebar navigation, I've tried to use vertical-align and line-height but there was no change, please see the code below:

HTML:

<div id="sidebar-wrapper">
  <ul class="sidebar-nav" id="MainMenu">
    <li class="sidebar-brand"><a href="#">ABC</a></li>
    <li><a href="#"><img src="images/icons/home.png">HOME</a></li>
  </ul>
</div>

Any help or guidance will be much appreciated.

Regards

like image 993
MOZ Avatar asked Mar 18 '23 19:03

MOZ


2 Answers

You can use vertical-align and line-height

<p style = 'line-height: 20px'>
  <img src = 'images/icons/home.png' style='vertical-align: middle' /> HOME
</p>

Another approach: You can use no-repeat for the background

span.yourtext{
  background: transparent url(images/icons/home.png) no-repeat 
              inherit left center;
  padding-left: 15px
}
<span class="yourtext">
  Home
</span>
like image 150
John Stephen Avatar answered Apr 28 '23 09:04

John Stephen


You can use Pseudo element to put the icons with text. In addition I would suggest you to choose FontAwesome Library to choose icons (its a vector based and you can change the font icons any time). Have a look at the DEMO I've made with FontAwesome Library. Check DEMO.

CSS Code is

ul{list-style-type:none;}
li{position:relative;}
li:not(.sidebar-brand):before{content:"\f015";position:absolute; left:-20px;font-family: FontAwesome;color:red;}
like image 26
Kheema Pandey Avatar answered Apr 28 '23 10:04

Kheema Pandey