从网格布局更改为弹性布局,响应迅速
我想根据媒体决议安排3个要素。在台式机上,我希望它们成为
box1 box2
box3
移动设备(最大宽度:800px)的响应模式,我希望它们为此,
box1
box2
box3
我认为我认为我需要在一般部分中使用
.box-container {
display: grid;
grid-template-columns: 60% 40%;
grid-auto-flow: column;
}
,并且
.box1 {
grid-row: 1 / 3;
background: lightblue;
}
随着媒体查询中的这种变化通过以某种方式覆盖这一点
@media only screen and (max-width: 800px) {
.box-container {
display: flex;
grid-template-columns: 100%;
flex-direction: column;
}
}
,部分并没有被覆盖,并且元素保持在网格视图中。当我将此代码放在一般部分中时,框相互显示。
https://codepen.io/tobwun/pen/pen/pen/pen/pen/mwqopjl
感谢您的任何帮助!
托比
I would like to have 3 elements arranged based on the media resolution. On Desktop I would like them to be
box1 box2
box3
and in responsive mode on mobile (max-width: 800px) I would like them to be
box1
box2
box3
For this I thought I need in my code to have in the general section
.box-container {
display: grid;
grid-template-columns: 60% 40%;
grid-auto-flow: column;
}
and
.box1 {
grid-row: 1 / 3;
background: lightblue;
}
with this changing in the media query section by overwriting this with
@media only screen and (max-width: 800px) {
.box-container {
display: flex;
grid-template-columns: 100%;
flex-direction: column;
}
}
However somehow this is not overwritten and elements stay in Grid view. When I put this code in the general section the boxes show up below each other.
https://codepen.io/tobwun/pen/MWQOpjL
Thanks for any help!
Toby
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需扭转
.box-container
CSS规则的顺序即可。将网格规则放在首先,然后在之后使用媒体查询 flex规则。将来,在您的问题中包括一个摘要 - 它是堆栈Overflow的codepen或jsfiddle的版本。
Just reverse the order of your
.box-container
CSS rules. Put the grid rule first, then the flex rule with the media query after it.And in future, include a snippet in your question — it’s Stack Overflow's version of a Codepen or jsFiddle.