【发布时间】:2012-10-31 19:38:05
【问题描述】:
我有带标题的图片,如下所示:
<figure class="imageBoxShadow">
<img alt="Alt-Text" src="http://lorempixel.com/280/375">
<figcaption>A Caption for this image</figcaption>
</figure>
“imageBoxShadow”类在图像周围放置了一个 boxShadow(谁会猜到?)。我把它放在图上,因为标题应该在边界内。只要标题比图像宽,它就可以正常工作。
但是,如果我有一个小图像和/或一个长标题,则标题将尽可能延长图形元素,这看起来很愚蠢。
当然我可以通过添加硬编码样式来设置宽度来限制图形元素:
<figure class="imageBoxShadow" style="width: 100px">
<img alt="Alt-Text" src="http://lorempixel.com/100/150">
<figcaption>Using a hardcoded style to restrict the figure element works but feels stupid.</figcaption>
</figure>
但这在 CMS 上下文中感觉很愚蠢而且不太方便。
有没有更好的方法来做到这一点?
有一个 jsFiddle 链接可以查看:http://jsfiddle.net/Sorcy/h5sNB/
【问题讨论】:
-
前几天我自己也在考虑这个问题,
<figure>和<figcaption>的布局很尴尬。