gpt4 book ai didi

html - 文本对齐中心按钮

转载 作者:行者123 更新时间:2023-11-28 04:55:48 24 4
gpt4 key购买 nike

我需要将按钮居中放置在页面中间,一个在另一个下面。

我使用了下面的代码,但结果是按钮仍然彼此相邻出现。

header {
text-align: center;
.btn {
@include Myriad-Pro-Light;
border-radius: 7px;
padding: 5px 10px;
border: none;
}
.btn-green {
color: #fff;
background: #7CAE9E;
margin: 20px;
}
.btn-grey {
color: #333;
background: $grey;
margin: 20px;
}
}
<header>
<a href="#" class="btn btn-default btn-green" role="button">Button A</a>
<a href="#" class="btn btn-default btn-grey" role="button">Button B</a>
</header>

谢谢

最佳答案

你可以为此使用“flexbox”

header {
display: flex;
flex-direction: column;
align-items: center;
.btn {
@include Myriad-Pro-Light;
border-radius: 7px;
padding: 5px 10px;
border: none;
}

.btn-green {
color: #fff;
background: #7CAE9E;
margin: 20px;
}

.btn-grey {
color: #333;
background: $grey;
margin: 20px;
}
}
<header>
<a href="#" class="btn btn-default btn-green" role="button">a</a>
<a href="#" class="btn btn-default btn-grey" role="button">b</a>
</header>

没有 flexbox

.btn {
@include Myriad-Pro-Light;
border-radius: 7px;
padding: 5px 10px;
border: none;
float: left;
clear: both;
width: calc(100% - 40px);
box-sizing: border-box;
text-align: center;
}
.btn-green {
color: #fff;
background: #7CAE9E;
margin: 20px;
}
.btn-grey {
color: #333;
background: $grey;
margin: 20px;
}
<header>
<a href="#" class="btn btn-default btn-green" role="button">a</a>
<a href="#" class="btn btn-default btn-grey" role="button">b</a>
</header>

关于html - 文本对齐中心按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40405678/

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