Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

align icons with text

What's the best way to align icons (left) and text (right) or the opposite text on left and icon on right?

Does the icon image and text have to be the same size? Ideally I would like them to be different but be on the same vertical alignment.

I am using background-position css property to get the icons from a larger image.

Here is how I do it now, but I am struggling with either getting them to be on the same line or be vertically aligned to the bottom.

Text

This is what I get after I try your suggestions.

Though the text is now aligned with the icon, it is superimposed over the icon to the right of the icon that I want. Please note that i am using the background position to show the icon from a larger set of images.

Basically I am getting

<icon><10px><text_and_unwanted_icon_to_the_right_under_it>
<span class="group3_drops_icon group3_l_icon" style="">50</span>

group3_drops_icon {
background-position:-50px -111px;
}

.group3_l_icon {
-moz-background-clip:border;
-moz-background-inline-policy:continuous;
-moz-background-origin:padding;
background:transparent url(/images/group3.png) no-repeat scroll left center;
height:35px;
overflow:hidden;
padding-left:55px;
}
like image 701
badnaam Avatar asked Jun 23 '10 23:06

badnaam


People also ask

How do I align text and icon on same line?

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.

How do I align text with icons in Word?

Hold down Shift and use the mouse or touchpad to select the objects that you want to align. Select Shape Format or Picture Format. Select Align. If you don't see Align on the Shape Format tab, select Arrange, and then choose Align.

How do I align text and icons in HTML?

Use flexbox for vertical centering A Flexbox can align elements in horizontal and vertical space to center text, icons or any other elements in CSS. This compact snippet turns our . container into a flex container which automatically turns its child elements into flex items.

How do you align a image along with the text?

To center an image using text-align: center; you must place the <img> inside of a block-level element such as a div . Since the text-align property only applies to block-level elements, you place text-align: center; on the wrapping block-level element to achieve a horizontally centered <img> .


2 Answers

I usually use background:

<style type="text/css"> .icon { background-image: url(path/to/my/icon.jpg); background-position: left center; background-repeat: no-repeat;  padding-left: 16px; /* Or size of icon + spacing */ } </style>  <span class="icon">Some text here</span> 
like image 147
rossipedia Avatar answered Sep 24 '22 03:09

rossipedia


You can do it on the same line using vertical-align and line-height

<p style='line-height: 30px'>
  <img src='icon.gif' style='vertical-align: middle' />Icon Text
</p>

Alternatively, you can go the background approach with no-repeat and positioning:

span.icontext {
  background: transparent url(icon.gif) no-repeat inherit left center;
  padding-left: 10px /* at least the width of the icon */
}

<span class="icontext">
  Icon Text
</span>
like image 37
Jamie Wong Avatar answered Sep 26 '22 03:09

Jamie Wong