合理性不适合CSS网格
在这种情况下,为什么要证明合理性:之间的空间不起作用?我想将最后一件项目推到右边缘,然后将中间物品置于中间的边缘。
div{
background: lightblue;
width: 8rem;
height: 8rem;
}
main{
margin: 2rem auto;
width: 80%;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5rem 0rem;
background: yellow;
justify-content: space-between;
}
<main>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</main>
Why justify-content: space-between doesnt work in this case? I want to push the last item to the right edge and center the middle one.
div{
background: lightblue;
width: 8rem;
height: 8rem;
}
main{
margin: 2rem auto;
width: 80%;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5rem 0rem;
background: yellow;
justify-content: space-between;
}
<main>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</main>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您快到了,但是您不应使用固定大小
8REM
(与您的盒子尺寸对齐),而不是使用分数单元fr
。fr
一直在拉伸您的网格框,因此,这就是为什么您不能在没有备用空间的情况下应用合理性
。You're almost there, but instead of using fractional unit
fr
, you should use a fixed size8rem
(aligned with your box size).fr
has been stretching your grid box, so that's why you cannot applyjustify-content
without spare space.//您必须使用百分比而不是绝对
//you must use percent not absolute