Фиксированные подписи к картинам
Использование тега figure и figcaption для создания подписей к изображениям
by Andrey Dobrovoi
HTML
<div class="example">
<figure class="ink-image bottom-space">
<figcaption>
Подпись размещяется вверху перед изображением.
</figcaption>
<img src="http://lorempixel.com/960/640/" class="imagequery">
</figure>
<figure class="ink-image bottom-space">
<img src="http://lorempixel.com/g/960/640/">
<figcaption>
Подпись размещяется внизу после изображения.
</figcaption>
</figure>
<figure class="ink-image bottom-space">
<img src="http://lorempixel.com/960/640/people/" class="imagequery">
<figcaption class="over-top">
Подпись поверх изображения, сверху, слегка прозрачный фон.
</figcaption>
</figure>
<figure class="ink-image bottom-space">
<img src="http://lorempixel.com/960/640/sports" class="imagequery">
<figcaption class="over-bottom">
Подпись поверх изображения, снизу, слегка прозрачный фон.
</figcaption>
</figure>
<figure class="ink-image>
<img src="http://lorempixel.com/960/640/sports" class="imagequery">
<figcaption class="center">
Подпись по центру.
</figcaption>
</figure>
<figure class="ink-image" style="float: left; width: 48%;">
<img src="http://lorempixel.com/960/640/sports" class="imagequery">
<figcaption class="dark">
Подпись на тёмном фоне
</figcaption>
</figure>
<figure class="ink-image" style="float: right; width: 48%;">
<img src="http://lorempixel.com/960/640/sports" class="imagequery">
<figcaption class="light">
Подпись на светлом фоне
</figcaption>
</figure>
</div>
CSS
html * {
box-sizing: border-box;
}
.example {
position: relative;
padding: 24px;
margin:0 auto;
width: 100%;
max-width: 600px;
}
/* Группируем картинки */
figure {
margin: 0px;
}
figure.ink-image {
position: relative;
border: 1px solid #555;
}
/* Размеры изображений */
figure.ink-image > img {
border: 0px none;
width: 100%;
vertical-align: top;
}
/* Формируем подписи к картинкам */
figcaption {
padding: 1em;
background: none repeat scroll 0% 0% #FFF;
line-height: 1.3;
font-family: 'Roboto', sans-serif;
font-weight: 400;
}
figcaption.over-top {
top: 0px;
background: none repeat scroll 0% 0% rgba(255, 255, 255, 0.5);
}
figcaption.over-bottom {
bottom: 0px;
background: none repeat scroll 0% 0% rgba(255, 255, 255, 0.5);
}
figcaption.over-bottom, figcaption.over-top, figcaption.center {
position: absolute;
width: 100%;
border: medium none;
}
figure.ink-image > figcaption.center {
background: none;
font-family: 'Roboto', sans-serif;
font-weight: 900;
color: white;
text-transform: uppercase;
text-align: center;
margin: 0;
top: 50%;
left: 50%;
font-size: 2rem;
transform: translate(-50%, -50%);
}
figure.ink-image > figcaption.dark {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.75);
padding: 4px 8px;
color: white;
margin: 0;
font: 14px Sans-Serif;
}
figure.ink-image > figcaption.light {
position: absolute;
bottom: 10px;
right: 10px;
background: rgba(255, 255, 255, 0.75);
padding: 4px 8px;
color: black;
margin: 0;
font: 14px Sans-Serif;
}
/* Нижний отступ от каждого блока (опционально для демо) */
.bottom-space {
margin-bottom: 2em;
}