【发布时间】:2018-02-23 10:58:52
【问题描述】:
我试图在图像底部显示一个简短的图像描述,现在它看起来像这样:https://www.bootply.com/render/Gwde8WHtot
但我希望绿色背景与图像对齐(而不是红色边框),这意味着文本的宽度和高度属性应该响应图像,而不是它所在的容器。
这是我当前的代码:
// CSS
.textoverimage {
position: absolute;
background: green;
font-family: 'Roboto', sans-serif;
font-size: 15px;
color: white;
word-wrap: break-word;
text-align: center;
width: 100%;
height: auto;
bottom: 0;
left:0;
padding: 5px;
z-index: 5;
border-radius: 0px 0px 3px 3px;
}
// HTML
<div class="container">
<div class="row">
<div id="0" class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-12">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg">
<div class="textoverimage">Random</div>
</a>
</div>
</div>
</div>
完整示例:https://www.bootply.com/Gwde8WHtot
有什么方法可以实现吗?如果在调整浏览器大小时调整列/图像大小,则文本也应该是响应式的。任何帮助是极大的赞赏!提前致谢。
【问题讨论】:
-
@AaronMcGuire 是的,它应该看起来像这样,但它应该位于图像底部的顶部,而不是下方
标签: html css image containers