Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material design icons, how to center them as text?

I've been trying to do some kind of navbar with MaterializeCSS with 3 links, each one of 33% width of the navbar, and I want to center the text inside the links (even the icons)

If I don't put left or right classes, the text and the icon doesn't stay in the same line... But if I put left class to the icon then it floats to the left, therefore given that the navbar is width:100%, the space between the icon and the text is too much.

Here is the HTML

<div id="secondary-navbar"><nav>
  <div class="nav-wrapper">
    <ul>
      <li>
        <a href="#!">
          <i class="material-icons left">event</i>Calendario
        </a>
      </li>
      <li>
        <a href="#!">
          <i class="material-icons left">location_on</i>Mapa
        </a>
      </li>
      <li>
        <a href="#!">
          <i class="material-icons left">apps</i>Galería
        </a>
      </li>
    </ul>
  </div>
</nav></div>

And the CSS

#secondary-navbar nav
{
    background:#ffffff;
}
#secondary-navbar nav .nav-wrapper ul li a
{
    font-size:1.2em;
}
#secondary-navbar nav .nav-wrapper ul li a .material-icons
{
    font-size:1.2em;
    margin-right:0.2em;
}
#secondary-navbar nav .nav-wrapper ul li a,
#secondary-navbar nav .nav-wrapper ul li a .material-icons
{
    color:#06207d;
}

#secondary-navbar nav .nav-wrapper ul li
{
    width:33%;  
}
#secondary-navbar nav .nav-wrapper ul li:nth-child(3)
{

    width:34%;
}

Here is a jsfiddle, I tried with inline-block to the icon, but then then navbar gets more than 56px height... https://jsfiddle.net/4aednm5d/

Do you have any idea about how to solve this?

like image 901
cnexans Avatar asked Oct 25 '15 19:10

cnexans


2 Answers

I generally use this:

.icon-align {
       vertical-align: text-bottom;
    }
<i class="material-icons md-18 icon align">check_circle</i>Auto Accepted</div>`
like image 74
dessertcook Avatar answered Oct 30 '22 04:10

dessertcook


Use

text-align: center;

for aligning text and icons in the center of the parent.

like image 22
Florin Pop Avatar answered Oct 30 '22 03:10

Florin Pop