gpt4 book ai didi

html - css html 在父 div 中居中 div

转载 作者:太空宇宙 更新时间:2023-11-03 20:40:16 25 4
gpt4 key购买 nike

为什么绿色按钮不会在红色父 div 中居中?

CSS

.button_green {
background-image: url('../Images/btn_bg.jpg');
width: 202px;
height: 30px;
text-align: center;
text-transform: capitalize;
color: white;
text-shadow: 2px 2px #000;
font-family: Arial;
vertical-align: text-bottom;
display: inline-block;
margin: 0 auto;
}

#col2_rightbuttons span {
display:inline-block;
vertical-align:middle;
margin:5 auto 0 auto;
}

HTML:

<div id="col2_rightbuttons" style="background-color:red;">
<div class="button_green">
<span>test2</span>
</div>
</div>

enter image description here

最佳答案

尝试使用 display: block 而不是 inline-block。另外,不需要在 div 中使用 span - 只需将两者结合起来并使用一个元素,最好是语义上更正确的 button

关于html - css html 在父 div 中居中 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27116392/

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