HTML CSS响应式设计中间4/0或2/2,但没有3/1
我目前已经制作了这样的按钮(我已经取出了无用的东西来重现问题):
CSS:
.containerWelcome{
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.buttonsWelcome {
width: 200px;
}
.disabled {
opacity: 0.6;
cursor: not-allowed;
}
html:
<div class="containerWelcome">
<button name="button1" onclick="location.href=something0"
class="buttonsWelcome" type="submit"
value="something0">something0
</button>
<button name="button2" onclick="location.href=something"
class="buttonsWelcome" type="submit"
value="something">something
</button>
<button name="button3" onclick=""
class="buttonsWelcome disabled" type="submit"
value="somethingelse0">somethingelse0
</button>
<button name="button4" onclick=""
class="buttonsWelcome disabled" type="submit"
value="somethingelse1">somethingelse1
</button>
</div>
如果我不放大,我将彼此相邻四个按钮。这很好。 如果我放大一点,或者我在另一台较小的笔记本电脑上,我有3个按钮,一个按钮下面。这有点丑陋。
如果我的缩小甚至更多,那么我有2个按钮的两个按钮。这很好。除了它们不是完全集中的,这有点奇怪。我想那是因为它们在容器的左侧?
我的主要问题是:我想从中央容器顶部从4个按钮到2个按钮,而在中间容器的底部则2个,而没有笨拙的阶段,顶部有3个按钮中央容器的中心容器的一个。
我还正在寻找一种将按钮置于容器中心的方法,但我想这并不重要。
I currently have made my buttons like so (I've taken off the useless stuff to reproduce the problem):
CSS:
.containerWelcome{
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.buttonsWelcome {
width: 200px;
}
.disabled {
opacity: 0.6;
cursor: not-allowed;
}
HTML:
<div class="containerWelcome">
<button name="button1" onclick="location.href=something0"
class="buttonsWelcome" type="submit"
value="something0">something0
</button>
<button name="button2" onclick="location.href=something"
class="buttonsWelcome" type="submit"
value="something">something
</button>
<button name="button3" onclick=""
class="buttonsWelcome disabled" type="submit"
value="somethingelse0">somethingelse0
</button>
<button name="button4" onclick=""
class="buttonsWelcome disabled" type="submit"
value="somethingelse1">somethingelse1
</button>
</div>
And if I don't zoom in, I have the four buttons next to each other. Which is good.
If I zoom in a little bit or if I'm on another smaller laptop I have 3 buttons and one below them. Which is sort of ugly.
If I zoom even more, I have 2 buttons on top of 2 others one. Which is good. Except, they're not perfectly centered, which is a bit weird. I guess that's because they're at the left of the container?
My main issue is: I would like to go from 4 buttons to 2 on top of the center container and 2 at the bottom of the center container WITHOUT having the awkard stage where there are 3 buttons on top of the center container and one at the botton of the center container.
I also am looking for a way to center the buttons in the center of the container, but that's less important I guess.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试此代码:
try this code:
最简单的方法是仅使用显示flex,不用担心,学习很容易学习,检查下面的解决方案并用它替换您的.containerwelcome样式。
the easiest way is to just use display flex, don't worry it's to simple to learn, check the solution below and replace your .containerWelcome style with it.