繁体   English   中英

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

[英]image caption left aligned under centered image

我有一些带有标题的图像。 图片应位于网站的中心,标题应显示在图片下方。 到目前为止非常简单,但这是问题所在:标题应左对齐,并从图片的左下角开始(例如报纸)

我可以考虑使用表的解决方案,但我不喜欢它,因为表是在这里显示表数据,而不是图像和图像标题

表解决方案:

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

嗯嗯嗯

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

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

要不然是啥? :)

我将使用<figure><figcaption>进行少量的display: table以获得所需的效果。

看这个例子

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

尝试这样的事情:

http://jsfiddle.net/tcF7M/1

将图片和标题括在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>

使用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