【发布时间】:2019-01-07 16:21:05
【问题描述】:
我需要在包含文本的 div 底部放置一个图像和文本。在关注了关于这个问题的各种帖子之后,我想出了这个Fiddle
HTML
<div class="container">
<div class="row">
<div id="col-lg-4" class="col-lg-4">
<div class="cta-text">
<h3>Heading text that Can span 2 or 3 lines</h3>
</div>
<p><strong>Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications. With Cascading Style Sheets (CSS) and JavaScript, it forms a triad of cornerstone technologies for the World Wide Web</strong></p>
<div class="cta-text">
<table>
<tr>
<td><img src="~/img/icon2.png" /></td>
<td valign="middle">
<a href="#">
<p><strong>More Info!</strong></p>
</a>
</td>
</tr>
</table>
</div>
</div>
<div class="col-lg-4">
<div class="cta-text">
<h3>Heading text that Can span 2 or 3 lines</h3>
</div>
<p><strong>Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications.</strong></p>
<div class="cta-text">
<table>
<tr>
<td><img src="~/img/icon2.png" /></td>
<td valign="middle">
<a href="#">
<p><strong>More Info!</strong></p>
</a>
</td>
</tr>
</table>
</div>
</div>
<div class="col-lg-4">
<div class="cta-text">
<h3>Heading text that Can span 2 or 3 lines</h3>
</div>
<p><strong>Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications. With Cascading Style Sheets (CSS) and JavaScript.</strong></p>
<div class="cta-text">
<table>
<tr>
<td><img src="~/img/icon2.png" /></td>
<td valign="middle">
<a href="#">
<p><strong>More Info!</strong></p>
</a>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
CSS
.col-lg-4 {
width: 33.33333333%;
height: 200px;
position: relative;
float: left;
position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
.container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.row {
margin-right: -15px;
margin-left: -15px;
}
.cta-text {
margin-top: 10px;
text-align: left;
}
p {
margin: 10px;
display: block;
}
table {
background-color: transparent;
position: absolute;
bottom: 0;
}
.cta-text h3 {
font-weight: 900;
line-height: 1.1em;
color: #d9232d;
}
但是,在浏览器上调整表格的绝对位置会使其与文本的其余部分重叠。请提出一种避免图像和上方文本重叠的方法,如果我可以更好地构建 HTML。
【问题讨论】: