gpt4 book ai didi

以页面为中心的 html 链接按钮

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

目前我正在尝试创建一些看起来像按钮的链接。它工作得很好,除了我希望能够水平对齐它们。这是我目前所拥有的:

.border {
display: table;
width: 220px;
height: 120px;
border: 2px solid #1E5034;
transition: all 250ms ease-out;
box-sizing: border-box;
border-spacing: 10px;
float:left;
}

.border:hover {
border-spacing: 2px;
}

a.btn {
display: table-cell;
vertical-align: middle;
text-align: center;
color: #ffffff;
font: 17.5px sans-serif;
text-decoration: none;
background-color: #1E5034;
line-height: 20px;
margin-bottom: 0;
}

a.btn:hover,
a.btn:focus,
a.btn:active,
a.btn:visited,
a.btn:link {
color: #ffffff;
background-color: #1E5034;
text-decoration: none;
cursor: pointer;
}
<div class="btn-grp">
<div class="border">
<a class="btn" href="#">Some really long text link #1</a>
</div>
<div class="border">
<a class="btn" href="#">Some other really long text link #2</a>
</div>
<div class="border">
<a class="btn" href="#">Some more really really long text link #3</a>
</div>
<div class="border">
<a class="btn" href="#">The last really long text link #4</a>
</div>
</div>

编辑: What I am trying to achieve

如果它有 display:inline-block; 它会搞乱高度格式而不是居中文本。

我正在尝试创建此处所示的内容,但随后也能够将其置于页面中心。

谢谢!

最佳答案

支持所有浏览器,包括 IE。

.btn-grp {
position: absolute;
top: 0%;
left: 50%;
transform: translate(-50%, 0%);
width: 80vw;
}

.border {
display: table;
width: 25%;
height: 120px;
border: 2px solid #1E5034;
transition: all 250ms ease-out;
box-sizing: border-box;
border-spacing: 10px;
float: left;
}

.border:hover {
border-spacing: 2px;
}

a.btn {
display: table-cell;
vertical-align: middle;
text-align: center;
color: #ffffff;
font: 17.5px sans-serif;
text-decoration: none;
background-color: #1E5034;
line-height: 20px;
margin-bottom: 0;
}

a.btn:hover,
a.btn:focus,
a.btn:active,
a.btn:visited,
a.btn:link {
color: #ffffff;
background-color: #1E5034;
text-decoration: none;
cursor: pointer;
}
<div class="btn-grp">
<div class="border">
<a class="btn" href="#">Some really long text link #1</a>
</div>
<div class="border">
<a class="btn" href="#">Some other really long text link #2</a>
</div>
<div class="border">
<a class="btn" href="#">Some more really really long text link #3</a>
</div>
<div class="border">
<a class="btn" href="#">The last really long text link #4</a>
</div>
</div>

如果您需要垂直居中的 4 个 div,请使用:

.btn-grp {
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%, -50%);
}

关于以页面为中心的 html 链接按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49376569/

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