Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to vertically align text next to a floated image?

Tags:

I want to vertically align a span after a floated image. I searched for it in stack overflow and find this post. but my image is floated.

<div>     <img style="width:30px;height:30px; float:left">     <span style="vertical-align:middle">Doesn't work.</span> </div> 

I give vertical-align:middle to image and nothing change!

Thanks

like image 514
Mosijava Avatar asked May 09 '12 12:05

Mosijava


People also ask

How to vertically align text next to the image using CSS?

We can also vertically align the text next to the image using flexbox. Use display: flex property of CSS and combine it with the align-items: center property.

How to align items to the center of a Flexbox using CSS?

For this, we will use CSS display property combined with align-items property. We need to create a parent element that contain both image and text. After declaring the parent element as flexbox using display: flex; we can align the items to the center using align-items: center;.

How do I Center an image in a flex container?

Put the display property and choose the "flex" value. It will represent the element as a block-level-flex container. Use the align-items property with the "center" value to place the items at the center of the container. Set the justify-content property to "center". Put the image’s maximum width to 100% with the max-width property.

How do I Center an image on a page?

Set the justify-content property to "center". Put the image’s maximum width to 100% with the max-width property. Set the flex-basis property of the "image" class to specify the initial main size of your image. Choose the font size of your text with the help of the font-size property.


1 Answers

Even though this is an extremely old post, you can achieve this using Flexbox:

div {   display: flex;   align-items: center;  }
<div>  <img style="width:30px;height:30px;" src="http://lorempixel.com/output/abstract-q-c-640-480-8.jpg" />  <span>Doesn't work.</span>  </div>

JsFiddle example

like image 136
The Codesee Avatar answered Oct 18 '22 14:10

The Codesee