Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic - ion-item text is not vertically centered when ion-icon is bigger

Tags:

I have a list of ion-items with an icon followed by text. When the icon size is smaller as seen on the image below, the text seems to vertically align itself to the center of the ion-item. But when the icon is bigger, the alignment is a bit off.

enter image description here

This is all I've added:

<ion-item>   <ion-icon class="icon ion-ios-clock-outline"></ion-icon>    Recent </ion-item> 

And the CSS:

.icon {  font-size: 35px;  color: #ffC977; } 

How can I fix this. I tried using vertical-align, align-item and align-self. None of them worked.

like image 716
user3607282 Avatar asked Feb 25 '16 09:02

user3607282


People also ask

How do I center text vertically in an element?

Answer: Use the CSS line-height property Suppose you have a div element with the height of 50px and you have placed some link inside the div that you want to align vertically center. The simplest way to do it is — just apply the line-height property with value equal to the height of div which is 50px .

How do I increase the size of an ion-icon?

Size. To specify the icon size, you can use the size attribute for our pre-defined font sizes. Or you can set a specific size by applying the font-size CSS property on the ion-icon component. It's recommended to use pixel sizes that are a multiple of 8 (8, 16, 32, 64, etc.)

How do I center font awesome icons vertically?

If you want to make a text appear vertically aligned next to a Font Awesome icon, you can use the CSS vertical-align property set to “middle” and also, specify the line-height property. Change the size of the icon with the font-size property.


1 Answers

Try this. Add a <span> element to the text, vertical-align only works with elements inline side by side :

CSS

.icon {  display: inline-block;  font-size: 35px;  color: #ffC977;  vertical-align: middle; }  .text{   display: inline-block;   vertical-align: middle; } 

HTML

<ion-item>   <ion-icon class="icon ion-ios-clock-outline"></ion-icon>    <span class="text">Recent</span> </ion-item> 
like image 191
Luís P. A. Avatar answered Sep 21 '22 17:09

Luís P. A.