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.
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.
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 .
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.)
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With