[英]How to layout a photo text grid side by side
有两种方法可以做到这一点。 我的解决方案涉及CSS CSS Grid的使用,这是一种非常干净的方法(需要注意的是IE11需要更多的处理能力)。
下面的代码片段具有一个用于桌面大小的断点,以显示两列,任何低于该列的内容都会叠加。
的HTML
<article>
<div class="text">Text
</div>
<div class="image">Image
</div>
<div class="text">Text
</div>
<div class="image">Image
</div>
<div class="text">Text
</div>
<div class="image">Image
</div>
</article>
的CSS
article {
display: grid;
grid-template-columns: 1;
grid-auto-rows: minmax(100px, auto);
background: grey;
}
.image,
.text {
background: red;
height: 100px;
}
.image {
background: green;
}
.text:nth-of-type(3) {
background: magenta;
}
.image:nth-of-type(4) {
background: blue;
}
@media screen and (min-width: 1025px) {
article {
display: grid;
grid-template-columns: repeat(2, 1fr);
background: grey;
}
.text:nth-of-type(3) {
grid-column: 2;
grid-row: 2;
}
}
码笔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.