gpt4 book ai didi

html - 在 CSS 和按钮对齐方面遇到困难

转载 作者:太空宇宙 更新时间:2023-11-04 14:11:31 25 4
gpt4 key购买 nike

我在尝试对齐按钮时遇到了一些麻烦,想要垂直和水平对齐它们(2 列,3 行)。

这是我在 Photoshop 中设计它的方式:

enter image description here

这是它的样子:

enter image description here

最初前景是居中的,看起来和设计上的一模一样,但是按钮没有正确对齐,所以一个 friend 告诉我我应该用一个 table 来修复它,它做到了,但现在我无法对齐按钮, 有什么建议吗?

下面的 HTML 和 CSS:

.Background {
background: #024068;
position: absolute;
left: 0px;
top: 0px;
width: auto;
height: auto;
z-index: 1;
}

.Foreground {
background: #03609b;
background-repeat: no-repeat;
-webkit-box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.75);
width: 50%;
margin: auto;
height: 1153px;
z-index: 2;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-around;
}

.table {
align-content: inherit;
}

.Button.ButtonTxt {
background: #5fa4d0;
border: none;
-webkit-box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.45);
-moz-box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.45);
box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.45);
transition: all 0.3s ease 0s;
width: 331px;
height: 159px;
opacity: 1;
z-index: 3;
font-size: 50px;
font-family: "Bebas Neue";
color: rgb(255, 255, 255);
line-height: 1.2;
text-align: center;
text-shadow: 0px 3px 7px rgba(0, 0, 0, 0.35);
}

.Button:hover {
opacity: 0.75;
}

.Button:active {
background-color: #1E5B82;
transition: none;
}
<body class="Background">
<div class="Foreground">
<table class="table">
<tr>
<td><input class="Button ButtonTxt" type="button" value="Button1"></td>
<td><input class="Button ButtonTxt" type="button" value="Button2"></td>
</tr>
<tr>
<td><input class="Button ButtonTxt" type="button" value="Button3"></td>
<td><input class="Button ButtonTxt" type="button" value="Button4"></td>
</tr>
<tr>
<td><input class="Button ButtonTxt" type="button" value="Button5"></td>
<td><input class="Button ButtonTxt" type="button" value="Button6"></td>
</tr>
</table>
</div>
</body>

最佳答案

我有一个没有表格的解决方案,使用 flex。我为行添加了容器元素(一行中的成对按钮)并使所有内容都成为 DIV。以整页大小查看。

.Background {
background: #024068;
}

.Foreground {
background: #03609b;
background-repeat: no-repeat;
-webkit-box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.75);
width: 50%;
margin: auto;
height: 1153px;
display: flex;
flex-direction: column;
justify-content: center;
}

.rowcontainer {
display: flex;
justify-content: space-between;
margin-bottom: 100px;
padding: 0 10px;
}

.Button.ButtonTxt {
background: #5fa4d0;
border: none;
-webkit-box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.45);
-moz-box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.45);
box-shadow: 0px 0px 35px 0px rgba(0, 0, 0, 0.45);
transition: all 0.3s ease 0s;
width: 331px;
height: 159px;
font-size: 50px;
font-family: "Bebas Neue";
color: rgb(255, 255, 255);
line-height: 159px;
text-align: center;
text-shadow: 0px 3px 7px rgba(0, 0, 0, 0.35);
}

.Button:hover {
opacity: 0.75;
}

.Button:active {
background-color: #1E5B82;
transition: none;
}
<body class="Background">
<div class="Foreground">
<div class="rowcontainer">
<div class="Button ButtonTxt" type="button" value="Button1">Button1</div>
<div class="Button ButtonTxt" type="button" value="Button2">Button2</div>
</div>
<div class="rowcontainer">
<div class="Button ButtonTxt" type="button" value="Button3">Button3</div>
<div class="Button ButtonTxt" type="button" value="Button4">Button4</div>
</div>
<div class="rowcontainer">
<div class="Button ButtonTxt" type="button" value="Button5">Button5</div>
<div class="Button ButtonTxt" type="button" value="Button6">Button6</div>
</div>
</div>
</body>

关于html - 在 CSS 和按钮对齐方面遇到困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42705386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com