CSS网格 - 在布局中使用NXN表的订单
我需要为3个产品制作产品比较表。每个都有一个图像(a),标题(b)和描述(c)。我使用CSS网格创建了此表布局:
1a | 1b | 1c |
2a | 2b | 2c |
3a | 3b | 3c |
,因此所有这些条目都在单独的 div
单元格中。这在桌面上很好。在移动设备上,我需要它:
1A |
2A |
3A |
:----: |
1B |
2B |
3B |
:----: |
1C |
2C |
3C |
.container {
display: grid;
grid-auto-flow: column;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 1fr auto auto;
grid-auto-columns: 1fr;
grid-gap: 5px;
}
.container > div {
border: 1px solid red;
}
@media screen and (max-width: 768px) {
/* .container {
grid-auto-flow: row;
} */
}
<div class="container">
<div class="item">1a</div>
<div class="item">1b</div>
<div class="item">1c</div>
<div class="item">2a</div>
<div class="item">2b</div>
<div class="item">2c</div>
<div class="item">3a</div>
<div class="item">3b</div>
<div class="item">3c</div>
</div>
有没有办法用给定的HTML入侵这种结构?任何铅都值得赞赏。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于媒体查询,您使用Flexbox:
图I
用于按组订购DIVS,请使用Flexbox属性
order
。将每个属性应用于html中的inline样式
属性(请参见示例a ):图II
如果您不希望任何内联样式陷入困境您的html,这是针对styleheet或
&lt; style&gt;
标签的CSS解决方案。 (请参见示例b )图III
如该屏幕截图所示,它按要求的顺序堆叠。
示例一个(内联样式)
示例B(样式表)
For the media query you use flexbox:
Figure I
For the ordering the divs by group use the flexbox property
order
. Apply each one to the inlinestyle
attribute in HTML (see Example A):Figure II
If you don't want any inline styles mucking up your HTML, here's a CSS solution for a styleheet or
<style>
tag. (see Example B)Figure III
As seen on this screenshot, it stacks in the order OP requested.
Example A (Inline Style)
Example B (Stylesheet)