Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align figcaption to bottom of image in figure

Tags:

html

css

layout

<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.

like image 543
Tyler Shuster Avatar asked Jun 13 '13 03:06

Tyler Shuster


People also ask

How do I center a Figcaption under an image?

Use text-align: center on figcaption to align the test to the center. Save this answer.

Does Figcaption go inside figure?

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.

How do I align an image to the bottom right in HTML?

To align the image to the right use attribute value as “right”. Example: HTML.


1 Answers

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;
}
like image 66
armordecai Avatar answered Oct 16 '22 03:10

armordecai