flexbox防止并排显示两个元素
在大屏幕上,我想要1行上的所有元素,在较小的屏幕上,我想要三行。基本上,我不希望仅在同一行上使用H1看到按钮。 Flexbox如何解决此问题?谢谢:)
<div class="buttoncontainer">
<button class="change">Change background</button>
<h1 id="currentcolor">currentcolor</h1>
<button class="change">Change background</button>
</div>
和CSS:
'''
.buttoncontainer {
display: flex;
flex-wrap: wrap;
height: 90vh;
justify-content: flex-start;
}
button {
border: 10px solid black;
font-size: xx-large;
text-shadow: #222;
box-shadow: 10vh;
margin: auto;
text-align: center;
line-height: 4.5;
height: 25%;
flex-wrap: wrap;
border-radius: 20px;
}
h1 {
border: 10px solid black;
margin: auto;
}
不想要这个:不好
所以我 对此
On large screens i want all elements on 1 row, on smaller i want three rows. Basically i dont want see button only with H1 on same row. How can flexbox solve this issue? thank you :)
<div class="buttoncontainer">
<button class="change">Change background</button>
<h1 id="currentcolor">currentcolor</h1>
<button class="change">Change background</button>
</div>
And css:
'''
.buttoncontainer {
display: flex;
flex-wrap: wrap;
height: 90vh;
justify-content: flex-start;
}
button {
border: 10px solid black;
font-size: xx-large;
text-shadow: #222;
box-shadow: 10vh;
margin: auto;
text-align: center;
line-height: 4.5;
height: 25%;
flex-wrap: wrap;
border-radius: 20px;
}
h1 {
border: 10px solid black;
margin: auto;
}
SO i dont want this :Bad one
But straight to thisGOod one
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,解决此问题的最简单方法是通过媒体查询。媒体查询可以使您轻松地设置最大或最小宽度,以便以某种方式发生事物。
https:> https:https://developer.mozilla.org/en-en-us/ DOCS/WEB/CSS/MEDIA_QUERIES/used_media_queries
从我的理解中,您可以将其设置为以便每当它少于某个分辨率(在这种情况下,我设置了900px),应将flex方向属性设置为'柱子'。
这应该解决您的问题。
So the easiest way to solve this problem would be through Media Queries. Media queries make it so you can easily set a max or min width for things to happen a certain way.
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
From what I'm understanding, you can set it so whenever it's less than a certain resolution (in this case I set 900px), the flex-direction property should be set to 'column'.
This should solve your problem.