Dus*_*Lee 36 html css alignment
我想要一个html图像与div标签的底部齐平.我似乎无法找到实现这一目标的方法.
这是我的HTML:
<div class="span8">
<img src="/img/play-shot1.jpg" class="text-center shadow">
</div>
Run Code Online (Sandbox Code Playgroud)
问题是div嵌套在具有填充或边距的其他div中.
Mat*_*ert 61
添加相对定位到包装div标签,然后将图像绝对定位在其中,如下所示:
CSS:
.div-wrapper {
position: relative;
height: 300px;
width: 300px;
}
.div-wrapper img {
position: absolute;
left: 0;
bottom: 0;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="div-wrapper">
<img src="blah.png"/>
</div>
Run Code Online (Sandbox Code Playgroud)
现在图像位于div的底部.
ajr*_*dio 10
使用弹性盒:
HTML:
<div class="wrapper">
<img src="pikachu.gif"/>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.wrapper {
height: 300px;
width: 300px;
display: flex;
align-items: flex-end;
}
Run Code Online (Sandbox Code Playgroud)
根据另一个答案的一些评论中的要求,图像也可以水平居中justify-content: center;