gpt4 book ai didi

html - 让两个 div 在页面上彼此对齐

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

如何让以下两个 div 居中显示在同一页面上?

HTML

    <div class="setRegularFont centerText buttonText"><a href="#">BUTTON 1</a></div>
<div class="setRegularFont centerText buttonText"><a href="#">BUTTON 2</a></div>

CSS

.buttonText {
width: 10%;
border: 1px solid #818181;
color: #818181;
margin-top: 2em;
padding: 1em;
display:inline-block;
}
.buttonText a,a:visited,a:active {
text-decoration: none;
color: #818181;
}
.buttonText a:hover, .buttonText:hover a {
color: #1f1f1f;
cursor: pointer;
}
.buttonText:hover {
border: 1px solid #1f1f1f;
}

fiddle here .

最佳答案

两种解决方案。您可以将这两个包装起来 <div>与另一个 <div>然后设置 text-align属性(property)center其中<div>使用 CSS,像这样:

#centered {
width: 100%;
text-align: center;
}
.buttonText {
width: 10%;
border: 1px solid #818181;
color: #818181;
margin-top: 2em;
padding: 1em;
display: inline-block;
}
.buttonText a,
a:visited,
a:active {
text-decoration: none;
color: #818181;
}
.buttonText a:hover,
.buttonText:hover a {
color: #1f1f1f;
cursor: pointer;
}
.buttonText:hover {
border: 1px solid #1f1f1f;
}
<div id="centered">
<div class="setRegularFont centerText buttonText"><a href="#">BUTTON 1</a>
</div>
<div class="setRegularFont centerText buttonText"><a href="#">BUTTON 2</a>
</div>
</div>

第二种解决方案是简单地设置 text-align你的属性(property)<body>center使用 CSS,像这样:

body {
text-align: center;
}

.buttonText {
width: 10%;
border: 1px solid #818181;
color: #818181;
margin-top: 2em;
padding: 1em;
display: inline-block;
}
.buttonText a,
a:visited,
a:active {
text-decoration: none;
color: #818181;
}
.buttonText a:hover,
.buttonText:hover a {
color: #1f1f1f;
cursor: pointer;
}
.buttonText:hover {
border: 1px solid #1f1f1f;
}
<div class="setRegularFont centerText buttonText"><a href="#">BUTTON 1</a>
</div>
<div class="setRegularFont centerText buttonText"><a href="#">BUTTON 2</a>
</div>

关于html - 让两个 div 在页面上彼此对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26497738/

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