As you can see I have a white solid border and there is a caption underneath the border. However, I want the caption to be under the picture but within the border, and centered. Here is my code:
.img-set {
display: block;
margin: 0 auto;
width: 700px;
border: 30px solid white;
}
.caption{
align-text: center;
margin: 0 auto;
font-size: 19px;
}
HTML:
<div align="center">
<img src="https://upload.wikimedia.
org/wikipedia/commons/b/bf/Mikhail_Tal_1982.jpg" class="img-set">
<div class="caption">
Tal smoking a cigarette
</div>
</div>
You cannot add any content to the border, but here is my solution on CodePen (note that I also made some useful changes to your code so it complies better to the standards).
The solution explained
I have removed the border from the image. I then wrapped the image in a
div
element (img-container
).I've set the container's background color to white, and set padding of 30 pixels. This way I achieved a visual border of 30 pixels for the image, which is inside that container.
Inside the div, after the image (
img-set
), there is also the caption. Note that I addedmargin-bottom: 30px;
to the image, so it looks better.Fixed your code. The border should be for all the elements within (in this case the image and caption)
--
HTML:
--
CSS:
(spacing added)