gpt4 book ai didi

html - 如何居中 html 元素?

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

我想把它放在我的 HTML 文件的中心:

<a href="kobe1.html"><u style="font-size:10px">click images for more information </u></a>

我试过了

a {
text-align: center;
}
<a href="kobe1.html"><u style="font-size:10px">click images for more information </u></a>

<center>
<a href="kobe1.html"><u style="font-size:10px">click images for more information </u></a>
</center>

a {
left: 50%;
}
<a href="kobe1.html"><u style="font-size:10px">click images for more information </u></a>

但是什么也没有发生。谁能帮帮我?

最佳答案

其他答案要么完全误解了 CSS 中文本对齐的工作原理,要么完全无法解释。

在 CSS 中,有两种主要类型的元素, block (如 <div><p><h1>)和内联(如 <span><a><u>)。

你不能投text-align: center在内联上,因为当您考虑它时,它没有任何意义(在一堆文本中将单个粗体字居中是什么意思?)。

但是,您可以转换 text-align: center在一个 block 上,这将使该 block 内的所有文本和内联与中心对齐。因此,正确的解决方案是找到最近的 block 父 block ,或者创建一个:

.centered {
text-align: center;
/* On the container */
}
.small {
font-size: 10px;
}
<div class="centered">
<a href="whatever"><u class="small">Text here!</u></a>
</div>

关于html - 如何居中 <u> html 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33840085/

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