Css 以下布局的最佳响应网格解决方案是什么?
我试图找出实现这种网格布局的最佳方法。当然,它必须具有响应能力,因此布局会发生变化并经历3种状态,从大屏幕到中屏幕再到小屏幕。我附上了一张我想要得到的图片。我使用的是引导功能,所以可以访问他们的网格功能,但我不确定这是否太复杂了 这样的布局是否更适合JS插件(砖石或类似插件),或者flexbox或CSS网格是否能够实现这样的效果Css 以下布局的最佳响应网格解决方案是什么?,css,layout,responsive-design,grid,Css,Layout,Responsive Design,Grid,我试图找出实现这种网格布局的最佳方法。当然,它必须具有响应能力,因此布局会发生变化并经历3种状态,从大屏幕到中屏幕再到小屏幕。我附上了一张我想要得到的图片。我使用的是引导功能,所以可以访问他们的网格功能,但我不确定这是否太复杂了 这样的布局是否更适合JS插件(砖石或类似插件),或者flexbox或CSS网格是否能够实现这样的效果 对于纯CSS网格来说,这是一个经典的场景。 下面是这方面的一个超级简单的实现(注意:有更好的方法可以做到这一点,更隐式和更简捷的版本甚至不需要一些断点,但这是理解发生了
对于纯CSS网格来说,这是一个经典的场景。 下面是这方面的一个超级简单的实现(注意:有更好的方法可以做到这一点,更隐式和更简捷的版本甚至不需要一些断点,但这是理解发生了什么的更清晰的方法) 我建议阅读本文以获得CSS网格规范的完整描述: 这是一个带有工作解决方案的代码笔: HTML
看看这个答案,它和你想要达到的目标很相似。我不知道引导,但这可以完美地与flexbox结合媒体查询。。。
<div class="grid">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
</div>
.grid {
display: grid;
grid-gap: 10px;
width: 100%;
/*no explicit height, let the children determine it */
}
.grid-item {
/*arbitrary height, could be less, more, or grow depending on the content */
height: 200px;
font-size: 32px;
color: white;
background-color: black;
text-align: center;
border: 2px solid white;
}
@media (min-width: 768px) {
.grid {
/* here we set the two column layout fr are special units for grids, it represents the available space */
grid-template-columns: 1fr 1fr;
}
}
@media (min-width: 1024px) {
.grid {
height: 400px;
/* here we set the four column layout, fr are special units for grids, it represents the available space */
grid-template-columns: 1fr 1fr 1fr 1fr;
/* here we set the two row layout, fr are special units for grids, it represents the available space */
grid-template-rows: 1fr 1fr;
}
.grid-item {
height: auto;
}
.grid-item:first-child {
/* here we set a special size for the first children of the grid */
grid-column: 1 / 3;
grid-row: 1 / 3;
}
}