【发布时间】:2016-07-03 05:56:10
【问题描述】:
参考下面的 HTML,有四个 DIV 容器,每个容器都包含一个图像、标题元素、段落元素和一个链接。当页面在全尺寸计算机显示器上打开时,我希望三个 div 在屏幕上并排对齐。
到目前为止,它们只是垂直堆叠在屏幕下方。
<div class="threeSpread">
<div class="outer">
<img src="imagesForNew/new1.jpg">
<h2>CHININESE INVESTORS COME TO DETROIT</h2>
<p>"the Shanghai-based developer Dongdu International (DDI) made its first move. In an online auction, it snapped up three iconic downtown properties, all built during the citys early 20th-century"</p>
<a href="http://www.theguardian.com/cities/2014/jul/22/does-multimillion-dollar-chinese-investment-signal-detroits-rebirth">theguardian.com</a>
</div>
<div class="inner">
<img src="imagesForNew/new1.jpg">
<h2>CHININESE INVESTORS COME TO DETROIT</h2>
<p>"the Shanghai-based developer Dongdu International (DDI) made its first move. In an online auction, it snapped up three iconic downtown properties, all built during the citys early 20th-century"</p>
<a href="http://www.theguardian.com/cities/2014/jul/22/does-multimillion-dollar-chinese-investment-signal-detroits-rebirth">theguardian.com</a>
</div>
<div class="outer">
<img src="imagesForNew/new1.jpg">
<h2>CHININESE INVESTORS COME TO DETROIT</h2>
<p>"the Shanghai-based developer Dongdu International (DDI) made its first move. In an online auction, it snapped up three iconic downtown properties, all built during the citys early 20th-century"</p>
<a href="http://www.theguardian.com/cities/2014/jul/22/does-multimillion-dollar-chinese-investment-signal-detroits-rebirth">theguardian.com</a>
</div>
</div>
CSS
div {
display: block;
}
.threeSpread {
margin: 0 40px 40px 40px;
}
div.inner, div.outer {
max-width: 30%;
}
@media (max-width: 568px) {
.outer img {
float: left;
margin-right: 5px;
}
.inner img {
float: right;
margin-right: 5px;
}
h2 {
margin-top: 50px
}
}
【问题讨论】:
-
将 3 个 div 与 flexbox 对齐:stackoverflow.com/a/32122011/3597276