我想在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>
但没有任何事情发生。有人可以帮助我吗?。
答案 0 :(得分:7)
其他答案要么显示出对CSS中文本对齐方式的完全误解,要么完全无法解释。
在CSS中,有两种主要类型的元素,块(如<div>
,<p>
和<h1>
)和内联(如<span>
,<a>
和<u>
)。
你不能在内联中投射text-align: center
,因为当你想到它时,它没有任何意义(将一个粗体字集中在一堆文本中意味着什么?)。 / p>
你可以然后在{strong>块上投放text-align: center
,然后在其中生成所有文字和内联阻止,与中心对齐。因此,正确的解决方案是找到最近的块父,或创建一个:
.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>
答案 1 :(得分:0)
只需使用div
我们可以写为
.centered {
text-align: center;
/* On the container */
}
.small {
font-size: 10px;
}
<div class="centered">
<a href="kobe1.html"><u class="small">click images for more information</u></a>
</div>
或
<div style="text-align:center">
<a href="kobe1.html"><u style="font-size:10px">click images for more information </u></a>
</div>