在边框底部定位标题

时间:2013-07-16 10:06:28

标签: html css

我正在尝试创建一个响应迅速的宝丽来相框。 问题是标题不会粘在底部边框上,它只是漂浮在图像上。

如果我使用像素而不是百分比,它可以工作,但不是其他方面。 有什么想法吗?

the fiddle

HTML

<div class="imageContainer">
  <img src="http://photogallery.indiatimes.com/beauty-pageants/miss-india/rochelle-maria-raos-photo-shoot/photo/16651703/Miss-India-International-Rochelle-Maria-Rao-during-her-photo-shoot-.jpg" />
    <p> Title</p>
</div>

CSS

.imageContainer {
    position: relative;
    width: 25%;
    padding-bottom: 25%;
    float: left;
    height: 0;
    margin-right:10px;
    border:10px solid #e3e3e3;
    border-bottom:30px solid #e3e3e3;
}

.imageContainer img {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
}
.imageContainer p{
    position:absolute;

}

2 个答案:

答案 0 :(得分:2)

您正在做的是不正确的,您在图像周围使用了粗边框,这阻止了内部文本在其上方流动,为了实现您需要为{{1}使用负bottom值}}

title

Demo

我建议您使用.imageContainer p{ position:absolute; bottom: -40px; } display: inline-block;元素与嵌套li&amp;标div标记imgdiv固定img minheight,标题元素位于widthabsolute

答案 1 :(得分:1)

将此添加到.imageContainer p声明:

bottom: -40px;