I want an html image to be flush with the bottom of a div tag. I can't seem to find a way to accomplish this.
我想要一个html图像与div标签的底部齐平。我似乎无法找到实现这一目标的方法。
Here is my HTML:
这是我的HTML:
<div class="span8">
<img src="/img/play-shot1.jpg" class="text-center shadow">
</div>
The problem is that the div is nested within other divs that have padding or margins.
问题是div嵌套在具有填充或边距的其他div中。
1 个解决方案
#1
50
Add relative positioning to the wrapping div tag, then absolutely position the image within it like this:
将相对定位添加到包装div标签,然后将图像绝对定位在其中,如下所示:
CSS:
CSS:
.div-wrapper {
position: relative;
height: 300px;
width: 300px;
}
.div-wrapper img {
position: absolute;
left: 0;
bottom: 0;
}
HTML:
HTML:
<div class="div-wrapper">
<img src="blah.png"/>
</div>
Now the image sits at the bottom of the div.
现在图像位于div的底部。
#1
50
Add relative positioning to the wrapping div tag, then absolutely position the image within it like this:
将相对定位添加到包装div标签,然后将图像绝对定位在其中,如下所示:
CSS:
CSS:
.div-wrapper {
position: relative;
height: 300px;
width: 300px;
}
.div-wrapper img {
position: absolute;
left: 0;
bottom: 0;
}
HTML:
HTML:
<div class="div-wrapper">
<img src="blah.png"/>
</div>
Now the image sits at the bottom of the div.
现在图像位于div的底部。