<figure>
<img src="http://lorempixel.com/x/x" alt="figure">
<figcaption>Nam elementum non massa at mattis.</figcaption>
</figure>
I'm creating a CSS file and want to place the figcaption with 100% width and a semi-transparent background-color on top of the image, but I want the bottom of the figcaption box and the bottom of the image to always be the same regardless of what image is used.
Use text-align: center on figcaption to align the test to the center. Save this answer.
HTML allows the figcaption element to be either the first or the last element inside the figure and, without any CSS rules to the contrary, that will cause the caption to be at the top or the bottom of the figure, respectively.
To align the image to the right use attribute value as “right”. Example: HTML.
Use absolute positioning on the figcaption element. Don't forget to set "position: relative" on the figure element, too. Here's an example: http://jsfiddle.net/armordecai/xL1bk6k7/
figure {
position: relative;
}
figure img {
display: block;
}
figcaption {
background: rgba(0, 0, 0, 0.5);
color: #FFF;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With