1

What is the easiest, quickest way to vertically align differently sized horizontally aligned images? Everything on Google is not working for me or I'm not doing it right... I've tried using the 'vertical-align' property in .media and .media img.

Here's my jsfiddle: http://jsfiddle.net/C8DKc/

HTML

<div id="main">
    <div id="avatar">
        <img src="http://i.imgur.com/GgxBXAA.png" />
    </div>
    <div class="media">
        <img src="http://i.imgur.com/GmT37TG.png" />
    </div>
</div>

CSS

body {
background-color: #e5e5e5;

}

#main {
    padding: 10px;
    display: inline-block;
    width: auto;
    background-color: red;
}

#avatar {
    display: inherit;
}

.media {
    display: inherit;
}

.media img {
    margin-left: 10px;
}
ErraticFox
  • 1,363
  • 1
  • 18
  • 30
  • 1
    Might have something to do with this: http://stackoverflow.com/a/2744005/2191572 but JoshC's answer looks spot-on! Normally a vertical align is used in the context of a `` so you need to have your `
    ` imitate a `` through the use of `display:table-cell;`. At least this is the easiest way =)
    – MonkeyZeus Jan 10 '14 at 00:06

3 Answers3

2

Change the parent, #main, to display:table-cell.

#main {
    padding: 10px;
    display: table-cell;
    width: auto;
    background-color: red;
}

Then add vertical-align:middle to .media (working example here)

.media {
    display: inherit;
    vertical-align: middle;
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
0

How to vertically align:

HTML

<div id="main">
    <div id="avatar" class="inner">
        <img src="http://i.imgur.com/GgxBXAA.png" />
    </div>
    <div class="media inner">
        <img src="http://i.imgur.com/GmT37TG.png" />
    </div>
</div>

CSS

body {
background-color: #e5e5e5;

}

#main {
    padding: 10px;
    display: inline-block;
    width: auto;
    background-color: red;

}

#avatar {
    display: inherit;
}

.media {
    display: inherit;
}

.media img {
    margin-left: 10px;
}

.inner{
    width: 100%;
    text-align: center;
}

Fiddle http://jsfiddle.net/6KJvj/

JerryHuang.me
  • 1,790
  • 1
  • 11
  • 21
0

You use display:block. Is this what you want?

http://jsfiddle.net/C8DKc/

body {
    background-color: #e5e5e5;
}

#main {
    padding: 10px;
    display: block;
    width: auto;
    background-color: red;
    width: 100px;
    margin: 0 auto;
}

#avatar {
    display: inherit;
}

.media {
    display: inherit;
}

.media img {
    margin-left: 10px;
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
guest
  • 2,185
  • 3
  • 23
  • 46