gpt4 book ai didi

html - 将链接对齐到 div 的底部并将其居中

转载 作者:行者123 更新时间:2023-12-04 12:52:17 25 4
gpt4 key购买 nike

我正在尝试将链接固定在 div 的底部中心并使其居中。

到目前为止,我已经想出了这个: http://jsfiddle.net/r494Lx0r/2/

div.container {
position: relative;
height: 110px;
width: 120px;
border: dashed 1px red;
}

div.container div.text {
position: absolute;
bottom: 0px;
border: solid 1px black;
}

现在我该如何让它居中呢?我尝试将 text-align:center;margin:0 auto; 添加到容器中,但它们都没有任何作用。

有人知道怎么做吗?

最佳答案

更新text-algin: center 添加到父级以使 anchor 居中并设置 border: solid 1px black; 到您的 anchor :

div.container {
position: relative;
height: 110px;
width: 120px;
border: dashed 1px red;
}

div.container div.text {
position: absolute;
bottom: 0px;
right: 0;
left: 0;
text-align: center;
}

a{border: solid 1px black;}
<div class="container">
<div class="text">
<a href="#">Google.com</a>
</div>

</div>

添加 Width: 100%text-align: center

div.container {
position: relative;
height: 110px;
width: 120px;
border: dashed 1px red;
}

div.container div.text {
position: absolute;
bottom: 0px;
text-align: center;
width:100%;
border: solid 1px black;
}
<div class="container">
<div class="text">
<a href="#">Google.com</a>
</div>

</div>

left: 0;, right: 0;text-align: center;

div.container {
position: relative;
height: 110px;
width: 120px;
border: dashed 1px red;
}

div.container div.text {
position: absolute;
bottom: 0px;
left: 0;
right: 0;
text-align: center;
border: solid 1px black;
}
<div class="container">
<div class="text">
<a href="#">Google.com</a>
</div>

</div>

or you can combine `margin-left: 50%;` and `transform: translate(-50%)`

div.container {
position: relative;
height: 110px;
width: 120px;
border: dashed 1px red
}

div.container div.text {
position: absolute;
bottom: 0px;
border: solid 1px black;
margin-left: 50%;
-webkit-transform: translate(-50%);
-moz-transform: translate(-50%);
transform: translate(-50%)
}
<div class="container">
<div class="text">
<a href="#">Google.com</a>
</div>

</div>

关于html - 将链接对齐到 div 的底部并将其居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27198088/

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