Skip to content Skip to sidebar Skip to footer

Place Caption Within Border Of Image

Here is my work so far. 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

Solution 1:

Fixed your code. The border should be for all the elements within (in this case the image and caption)

--

HTML:

<head></head><body><h1align="center">Mikhael Tal</h1><h5align="center">The magician from Riga</h5><figureclass="img-set"><imgsrc="https://upload.wikimedia.org/wikipedia/commons/b/bf/Mikhail_Tal_1982.jpg"><figcaptionalign="center">Mikhael Tal smoking a cigarette</figcaption></figure></body></html>

--

CSS:

h1 {
  font-size: 100px;
  font-family: italic;
}

h5 {
  font-size: 45px;
  font-family: italic;
  font-style: italic;
}

body {
  background-color: lightblue;
}

.img-set {
  border: 30px solid white;
  width: 700px;

  margin: 0 auto;
}

.img-setimg {
  display: block;
  width: 100%;
}

figcaption{
  background-color: #FFF;
  padding-top: 30px;
}

(spacing added)

Solution 2:

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.

.image-container {
  background-color: #ffffff;
  display: inline-block;
  padding: 30px;
}

Inside the div, after the image (img-set), there is also the caption. Note that I added margin-bottom: 30px; to the image, so it looks better.

Post a Comment for "Place Caption Within Border Of Image"