Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to vertical align the following content without using table cell

Tags:

html

css

I have the following structure:

div {
  display: table;
}
img {
  display: table-cell;
}
span {
  display: table-cell;
  vertical-align: middle;
}
<div>
  <img src="http://placehold.it/200x100" /> <span>Test</span>

</div>

It seems to work but I want to know if there is an alternative without using table. If I don't use table and just use:

span {vertical-align: middle;} 

It doesn't work!

I appreciate any help.

like image 355
Vagtepes Avatar asked Dec 01 '25 02:12

Vagtepes


1 Answers

Vertically align the image and the span.

HTML

<div>
  <img src="http://placehold.it/200x100" /> <span>Test</span>
</div>

CSS

img,
span {
    vertical-align:middle;
}

http://jsfiddle.net/dc2jn8vk/

like image 145
chrisbedoya Avatar answered Dec 02 '25 18:12

chrisbedoya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!