HTML は、3 番目の子 div を除いて、あなたのものとほぼ同じです。テキストを<span>
div でラップすると、それがa.imageCount
リンクに含まれます。
<div class="centered">
<a class="image-link" href="">
<img src="http://placekitten.com/100/100" width="100" height="100" />
</a>
<a class="image-link" href="">
<img src="http://placekitten.com/110/110" width="100" height="100" />
</a>
<a href="#photos" class="imageCount">
<span>some text</span>
</a>
</div>
CSS は次のようになります。
.centered {
width: 500px;
height: 300px;
background-color: #EEE;
text-align: center;
}
a {
text-decoration: none;
outline: 1px dotted blue; /* optional to show content boxes */
}
.image-link {
display: inline-block;
vertical-align: bottom; /* try out: bottom, middle, top */
}
.image-link img {
vertical-align: bottom; /* get rid of small white space below images */
}
.imageCount {
display: inline-block;
border: 1px solid blue;
padding: 5px;
border-radius: 5px;
background-color: lightgray;
margin-left: 10px;
}
.imageCount span {
/* in case you need to style the text in a special way */
}
デモ フィドルはhttp://jsfiddle.net/audetwebdesign/uBVHC/で見ることができます。
仕組み
基本的に、 にはインライン ブロックの子要素が 3 つdiv.centered
あるため、テキストの配置は期待どおりに機能します。
画像の 1 つが行の中で最も高い要素になり、 の配置をある程度制御したいと思いますa.imageCount
。
vertical-align
プロパティをに適用する.image-link
と、画像が要素に対して垂直方向にどのように配置されるかが決まりますa.imageCount
。3 つの主要な値 (上、中、下) を試して、必要なデザインに適した値を選択できます。
上 (または下) の位置を調整したい場合は、単に上 (または下) マージンを使用.imageCount
しdisplay: top (or bottom)
ます.image-link
。
の左マージンで水平方向の間隔を調整できます.imageCount
。