別のアプローチ。
メッセージとアイコンを子スパンのあるスパンに「関連付ける」ことを好みます。このアプローチの 2 つの鍵:
コンテナーdiv を親の div 内で垂直方向に揃えます。両方のクラスでpositionを使用し、containerでmarginを使用すると、それを実現できます。
スパンを親スパン内のメッセージと垂直に揃えます (アイコン付きのスパンで、 icon-messageクラスを使用します)。CSS コードのコメントを参照してください。
すべてのブラウザで動作します。
HTML
<div class="parent">
<div class="container">
<span class="icon-message">
<span>message</span>
</span>
</div>
</div>
CSS
.parent {
background-color: lightgrey ;
width: 100% ;
height: 70px ;
text-align: center ;
position: relative;
}
.container {
position: absolute;
display: inline-block;
height: 40px ;
top: 0;
bottom: 0;
margin: auto;
border: 1px solid #000;
}
.icon-message {
background: url( "http://upload.wikimedia.org/wikipedia/commons/8/88/Red_triangle_alert_icon.png" ) no-repeat;
display: inline-block;
background-size: 40px 40px; /* image's size */
height: 40px; /* image's height */
padding-left: 50px; /* image's width plus 10 px (margin between text and image) */
}
.icon-message span {
height: 40px; /* image's height */
display: table-cell;
vertical-align: middle;
}