这真令人沮丧!如何制作< H2>去图像的底部,而不是文本的底部?
https://codepen.io/TylerL-uxai/pen/gRxMqG/
<div class="col-lg-4">
<div class="header-link">
<img src="https://image.ibb.co/haP17k/umbrella.jpg" width="300" height="auto" alt="umbrella" border="0">
<h2>Artificial Intelligence & Blockchain Interest</h2>
</div>
<p>Learning more every day about Ethereum and other blockchain technologies!</p>
<p><a class="btn btn-primary" href="#" role="button">View details »</a></p>
</div>
</div>
答案 0 :(得分:2)
喜欢这样吗?
<img>
替换为<div>
并将图片用作该div的背景position: relative
应用于div position: absolute
应用于h2,因为绝对定位的元素位于在相对于其最近的祖先的指定位置
(MDN)
.header-img {
position: relative;
background: url('https://image.ibb.co/haP17k/umbrella.jpg') center center no-repeat / 100% 100%;
height: 300px;
width: 300px;
}
h2 {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: 0 auto;
}
&#13;
<div class="col-lg-4">
<div class="header-link">
<div class="header-img">
<h2>Artificial Intelligence & Blockchain Interest</h2>
</div>
</div>
<p>Learning more every day about Ethereum and other blockchain technologies!</p>
<p><a class="btn btn-primary" href="#" role="button">View details »</a></p>
</div>
</div>
&#13;