0

On this question there is a great solution on how to add centred image to the page.

  • Pure CSS solution
  • Not breaking the document flow (no floats or absolute positioning)
  • Cross browser compatibility (even IE6)
  • Completely responsive.
  • vertically centered

The solution http://jsfiddle.net/avrahamcool/d89xh/

* {
  padding: 0;
  margin: 0;
}
#over {
  position: absolute;
  width: 100%;
  height: 100%;
  text-align: center;
}
.Centerer {
  display: inline-block;
  height: 100%;
  vertical-align: middle;
}
.Centered {
  display: inline-block;
  vertical-align: middle;
}
<div id="over">
  <span class="Centerer"></span>
  <img class="Centered" src="http://th07.deviantart.net/fs71/200H/f/2013/236/d/b/bw_avlonas_a5_beach_isles_wallpaper_image_by_lemnosexplorer-d6jh3i7.jpg" />
</div>

But how to modify that solution to add an extra text just underneath the centered image so it will be always centered as well.

Picture of desired output

Any thoughts?

Community
  • 1
  • 1
Sergino
  • 10,128
  • 30
  • 98
  • 159

1 Answers1

4

You can use <figure> and <figcaption>:

<figure>
  <img />
  <figcaption>Image</figcaption>
</figure>

And give the parent element, text-align: center;.

Snippet

.center {text-align: center;}
<div class="center">
  <figure>
    <img src="http://placehold.it/250?text=IMG" alt="">
    <figcaption>Hello</figcaption>
  </figure>
</div>

Preview:

Fiddle: http://jsfiddle.net/0p53fxgk/

Preview:

Cross Browser Check

  • Internet Explorer 9
  • IE Edge
  • Firefox
  • Chrome
  • Opera

For IE below 9, you can use:

figure, figcaption {display: block;}
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252