Caption Hover Effects
Caption Hover Effects
Caption Hover Effects
The Markup
The structure of our grid and the figures will be made of an
unordered list and each item will contain a
The
figure
figure
figcaption
element.
Please note that using a figure only makes sense if it does not
constitute the main content itself but if its typically
referenced from the main flow of the document and if we can
move it away (to an appendix for example). Read more about
the figure element in this great HTML5 Doctor article: The
figure & figcaption elements.
This is the default structure for all the grid examples. Note
that for effect 4 we will have an additional division wrapping
the image.
The class for each single effect will be added to the list; so
example 1 will have cs-style-1, example 2 will have csstyle-2 and so on. Thats how we will define the effect styles
for each single example.
But first lets define the common styles for all effects.
The CSS
Note that the CSS will not contain any vendor prefixes, but
you will find them in the files.
The common styles for all the figures is the following. First,
well define the styles for the grid and the list items that will
serve as the containers of our figures:
.grid { padding: 20px 20px 100px 20px;
max-width: 1300px;
margin: 0
auto;
list-style: none; text-align: center; } .grid li {
display: inline-block;
width: 440px;
margin: 0;
padding: 20px;
text-align: left;
position:
relative; }
figure
margin: 0;
position: relative; }
The
figcaption
display: block;
position: relative; }
padding: 20px;
And finally, lets define some styles for the text elements and
the link:
.grid figcaption h3 {
margin: 0;
padding: 0;
color: #fff; } .grid
figcaption span:before {
content: 'by '; } .grid figcaption a { text-align: center;
padding: 5px 10px;
border-radius: 2px;
display: inline-block;
background: #ed4e6e;
color: #fff; }
Well add the by for the span that contains the author name
using the pseudo-class :before. Of course you can add that in
the HTML, but this will give you the freedom to change it
easily into something like made by or Designer: or similar.
Be careful not to remove meaning from your HTML, though, by
doing something like this.
In the end of our CSS we will also add a media query for
smaller screens:
@media screen and (max-width: 31.5em) {
100px 10px;
}
.grid li {
300px; } }
.grid {
width: 100%;
Effect 1
figcaption a bit:
.no-touch .cs-style-1 figure:hover figcaption, .cs-style-1 figure.cs-hover figcaption {
opacity: 1;
transform: translate(15px, 15px); }