CSS网格列根据屏幕化
我正在尝试使用CSS网格,并且列应该以这样的方式行事:
- 在移动屏幕上,我想要一个列女巫具有完整的宽度。该列包括两个部分。在第一部分中,有多个输入字段(也只有一个列)。在第二部分中,有两个列有较小的输入字段。
- 在较大的屏幕上(1024px或更宽),应该有两个列,以便两个部分相互相邻,而第一部分应小于第二部分。在第一部分中,输入字段现在分为两列,在第二部分中,输入字段分为三列。
我希望这是有道理的:)
我现在拥有的有效作品,但是这两个部分具有相同的宽度。我真的不想要这样,因为像第二部分一样,如果屏幕更宽,则很晚。因此,如果我有例如800px的浏览器宽度,那么即使第二部分可以安装在旁边,第一部分的右侧也有很多空白。
这就是我到目前为止的事情:
.surrounding-div {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(260px, 50%), max(600px, 50%)));
};
.first-section {
display: grid;
grid-template-columns: repeat(auto-fit, 200px);
grid-column-gap: 1rem;
}
.second-section {
display: grid;
grid-template-columns: repeat(auto-fit, 150px);
grid-column-gap: 1rem;
}
这可能是一种非常糟糕的方法,因为这是我第二次真正使用网格。我什至不确定是否在此处使用网格。
如果可能的话,我想在不使用媒体查询的情况下完成此操作
I'm trying to use CSS grid and the columns should behave like this:
- on a mobile-screen I want one column witch has the full width. That column includes two sections. In the first section there are multiple input fields (also only one column). In the second section there are two columns with smaller input fields.
- on a bigger screen (1024px or wider) there should be two columns so that the two sections are next to each other, while the first section should be smaller than the second. In the first section the input fields are now in two columns, in the second section the input fields are in three columns.
I hope that makes sense :)
What I have right now kind of works but the two sections have the same width. I don't really want it that way because like that the second section is "jumping up" very late if the screen gets wider. So if I have a browser-width of for example 800px then there is a lot of white space on the right of the first section even though the second section could fit next to it.
This is what I've got so far:
.surrounding-div {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(260px, 50%), max(600px, 50%)));
};
.first-section {
display: grid;
grid-template-columns: repeat(auto-fit, 200px);
grid-column-gap: 1rem;
}
.second-section {
display: grid;
grid-template-columns: repeat(auto-fit, 150px);
grid-column-gap: 1rem;
}
It is possible that this is a really bad approach, since this is only the second time that I really work with grids. I'm not even sure anymore if a grid is the right thing to use here.
If possible, I want to accomplish this without using Media Queries
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为此使用
@Media屏幕
。例如:使用此功能您可以设置每列的大小。 This might help you as well: https://www.w3schools.com/css/css3_mediaqueries_ex.asp
You can use
@media screen
for that. For example:Using this you can set the size of each column. This might help you as well: https://www.w3schools.com/css/css3_mediaqueries_ex.asp
您可以使用媒体查询。
如果您不太熟悉媒体查询或“ fr”概念,请使用谷歌搜索,如果您仍然有疑问,请引起评论。我将编辑我的答案,以包括它们。
You can use media queries.
If you're not too familiar with media queries or the 'fr' concept, google it and if you still have some doubts, do pop a comment. I'll edit my answer to include them.