简体   繁体   English

图像标题在居中图像下方对齐

[英]image caption left aligned under centered image

I have some images with captions. 我有一些带有标题的图像。 The images are centered on the sites and the caption should be shown under the images. 图片应位于网站的中心,标题应显示在图片下方。 Very simple so far but here's the problem: the captions should be left-aligned and start under the bottom-left-corner of the image (like in newspapers) 到目前为止非常简单,但这是问题所在:标题应左对齐,并从图片的左下角开始(例如报纸)

I can think of a solution with tables but I don't like it because tables are here to show table data and not images and image captions 我可以考虑使用表的解决方案,但我不喜欢它,因为表是在这里显示表数据,而不是图像和图像标题

table solution: 表解决方案:

<table class="centered-table">
  <tr><td class="image"><img src="stackoverflow.jpg" /></td></tr>
  <tr><td class="caption">Unanswered question on stackoverflow.com</td></tr>
</table>

Hmmmmmmm 嗯嗯嗯

<style>
    .centered {text-align:center;}
    .wrapper {display:inline-block; text-align:left;}
</style>

And

<div class="centered">
    <div class="wrapper">
        <div class="image"><img src="someimage.jpg" /></div>
        <div class="caption">Some caption text!</div>
    </div>
    <div class="wrapper">
        <div class="image"><img src="someimage.jpg" /></div>
        <div class="caption">Some caption text!</div>
    </div>
</div>

or what? 要不然是啥? :) :)

I would use <figure> and <figcaption> with a tiny bit of display: table to get the effect you want. 我将使用<figure><figcaption>进行少量的display: table以获得所需的效果。

See this Example 看这个例子

使用嵌套的div标签是另一种解决方案,如以下相关问题所示: 正确对齐图像标题

Try something like this: 尝试这样的事情:

http://jsfiddle.net/tcF7M/1 http://jsfiddle.net/tcF7M/1

Enclose your picture and title in a div, and give it an inline-block display style. 将图片和标题括在div中,并为其赋予行内显示样式。

<div id="article">
    <div class="title"><div>
        <img src="picture.jpg" />
        <em>Caption for the picture.</em>
    </div></div>
    <p>rest of the articlce...</p>
</div>

With CSS. 使用CSS。

div.title
{
    text-align:center;
}
div.title > div
{
    display:inline-block;
    text-align:left;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM