Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Center align text with icon [duplicate]

Using material icons with CSS, I have the following code that renders a link with icon and text.

<a href="#"><i class="material-icons">group_work</i>Groups</a>

As you can see in the image below, the text seems to be sinking down.. I would like them to be vertically aligned center together. How can i achieve this?

Icon and Text mis-aliged

PS. (Not a designer!)

like image 615
Vijay Chavda Avatar asked Oct 11 '16 14:10

Vijay Chavda


1 Answers

To vertically center elements, you can use the vertical-algin: middle; rule. In your case, that would most propably be:

.material-icons {
  vertical-align: middle;
}

Here is an example with your dark button:

.material-icons {
  vertical-align: middle;
  margin-right: 5px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<a href="#" class="grey darken-3 btn"><i class="material-icons">group_work</i>Groups</a>
like image 146
andreas Avatar answered Oct 09 '22 18:10

andreas