<div class="container">
<p>
<strong>The following examples show table displays used for aligning content with an image. First and second examples show centered alignment. Third shows top alignment, and fourth shows bottom alignment.</strong>
</p>
<hr>
<div class="flag">
<div class="flag__image">
<img src="http://tympanus.net/codrops-playground/assets/images/cssref/properties/display/smiley.jpg" alt="" />
</div>
<div class="flag__body">
<h2>vertical-align: middle</h2>
</div>
</div>
<hr />
<div class="flag flag--rev">
<div class="flag__body">
<h2>vertical-align: middle</h2>
</div>
<div class="flag__image">
<img src="http://tympanus.net/codrops-playground/assets/images/cssref/properties/display/smiley.jpg" alt="" />
</div>
</div>
<hr />
<div class="flag flag--top">
<div class="flag__image">
<img src="http://tympanus.net/codrops-playground/assets/images/cssref/properties/display/smiley.jpg" alt="" />
</div>
<div class="flag__body">
<h2>vertical-align: top</h2>
</div>
</div>
<hr />
<div class="flag flag--bottom">
<div class="flag__image">
<img src="http://tympanus.net/codrops-playground/assets/images/cssref/properties/display/smiley.jpg" alt="" />
</div>
<div class="flag__body">
<h2>vertical-align: bottom</h2>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</p>
</div>
</div>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #f0fbe7;
color: #555;
font-size: 1.1em;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.container {
margin: 40px auto;
width: 90%;
}
hr {
margin: 20px 0;
}
/**
* Flag object.
*
* Very similar to the media object, only the flag object allows for vertical alignment.
* stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/
*/
.flag {
display: table;
width: 100%;
}
.flag__image,
.flag__body {
display: table-cell;
vertical-align: middle;
}
.flag--top .flag__image,
.flag--top .flag__body {
vertical-align: top;
}
.flag--bottom .flag__image,
.flag--bottom .flag__body {
vertical-align: bottom;
}
.flag__image {
padding-right: 10px;
}
.flag__image > img {
display: block;
max-width: none;
}
.flag--rev .flag__image {
padding-right: 0;
padding-left: 10px;
}
.flag__body {
width: 100%;
}