CSS: dynamic image captions with transitions
by gabrieleromanato
HTML
<div id="slideshow">
<div id="slideshow-wrapper">
<figure class="slide">
<img src="https://lh3.googleusercontent.com/-dBlww3_uc0c/T1tEOigFdMI/AAAAAAAAA8A/8UgXM2_XCEk/s500/writer.jpg" alt="" width="200" height="150"/>
<figcaption id="f1">Caption 1</figcaption>
</figure>
<figure class="slide">
<img src="https://lh4.googleusercontent.com/-kHPpKCBXtd8/T1OoARO_KUI/AAAAAAAAA5M/XSv-V_qISH8/s500/the-thinker.jpg" alt="" width="200" height="150"/>
<figcaption id="f2">Caption 2</figcaption>
</figure>
<figure class="slide">
<img src="https://lh3.googleusercontent.com/-QToSdEntl2I/T2DQ05GbotI/AAAAAAAAA8o/SYJam552Ur4/s391/prepare-publish.jpg" alt="" width="200" height="150"/>
<figcaption id="f3">Caption 3</figcaption>
</figure>
</div>
<div id="slideshow-nav">
<a href="#f1">1</a>
<a href="#f2">2</a>
<a href="#f3">3</a>
</div>
</div>
CSS
#slideshow {
width: 615px;
margin: 2em auto;
}
#slideshow-wrapper {
width: 100%;
height: 150px;
}
.slide {
width: 200px;
height: 150px;
float: left;
margin: 0 5px 0 0;
position: relative;
overflow: hidden;
display: block;
}
.slide img {
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.slide figcaption {
position: absolute;
bottom: 0;
left: -200px;
width: 100%;
text-align: center;
padding: 5px 0;
background: rgba(0, 0, 0, 0.7);
color: #fff;
-moz-transition: all 600ms ease-in;
-webkit-transition: all 600ms ease-in;
-o-transition: all 600ms ease-in;
-ms-transition: all 600ms ease-in;
transition: all 600ms ease-in;
}
.slide figcaption:target {
left: 0;
}
#slideshow-nav {
margin: 1em 0;
text-align: center;
}
#slideshow-nav a {
color: #000;
text-decoration: none;
padding: 4px 8px;
border: 1px solid #ccc;
margin-right: 1em;
display: inline-block;
}