gpt4 book ai didi

html - Bootstrap - 无法让按钮居中

转载 作者:太空宇宙 更新时间:2023-11-04 11:08:42 27 4
gpt4 key购买 nike

我想要做的就是将一个按钮置于图像顶部的中央。我已经这样做了很多次,但这里确实有些不对劲,我无法弄清楚它是什么。当按钮不是绝对时,按钮以图像为中心。我把它设为绝对,所以它位于图像的顶部,但突然偏离了中心。

我这里有一个 Bootply 示例:http://www.bootply.com/eHq2b3ydhH

我觉得我只是没有看到明显的东西,但真的不知道它是什么。

最佳答案

解决方案:包装元素。
请注意,您的图像 (363x363) 小于您的列。

Bootply

HTML

<div class="button-wrapper">
<a class="btn btn-orange" href="#" role="button">Search</a>
</div>

CSS

#grid .btn-orange{
font-size:18px;
padding:10px;
background:#fcaf17;
color:#fff;
border:2px solid white;
border-radius:10px;
text-transform:uppercase;
margin: 0 auto;
}

.button-wrapper{
position: absolute;
width: 100%;
bottom: 45px;
}

第二个解决方案:'左:50%; margin-left: - <50% 的元素宽度>;´

Bootply

#grid .btn-orange {
left: 50%;
margin-left: -50px;
display: block;
}

关于html - Bootstrap - 无法让按钮居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33786463/

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