Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 为什么可以';使用页边距将文本居中:自动_Html_Css - Fatal编程技术网

Html 为什么可以';使用页边距将文本居中:自动

Html 为什么可以';使用页边距将文本居中:自动,html,css,Html,Css,我知道像这样的问题似乎很多,但我找不到一个与我的问题相匹配的 即使是在w3schools网站上,Chrome版本88.0.4324.104(官方版本)(64位)和Edge版本88.0.705.50(官方版本)(64位)中的文本也不居中。文本保持左对齐 该网站的代码为: <!DOCTYPE html> <html> <head> <style> .center { margin: auto; width: 60%; border: 3px

我知道像这样的问题似乎很多,但我找不到一个与我的问题相匹配的

即使是在w3schools网站上,Chrome版本88.0.4324.104(官方版本)(64位)和Edge版本88.0.705.50(官方版本)(64位)中的文本也不居中。文本保持左对齐

该网站的代码为:

<!DOCTYPE html>
<html>
<head>
<style>
.center {
  margin: auto;
  width: 60%;
  border: 3px solid #73AD21;
  padding: 10px;
}
</style>
</head>
<body>

<h2>Center Align Elements</h2>
<p>To horizontally center a block element (like div), use margin: auto;</p>

<div class="center">
  <p>Hello World!</p>
</div>

</body>
</html>

.中心{
保证金:自动;
宽度:60%;
边框:3px实心#73AD21;
填充:10px;
}
居中对齐元素
要使块元素水平居中(如div),请使用margin:auto

你好,世界

那么,如果我甚至不能让w3schools示例工作,我如何将文本置于中心呢


谢谢。

边距:自动将块元素的位置居中。该div正在居中,但这只是框本身居中,而不是框中的文本


文本对齐:居中
使文本(和其他内联元素)在其容器内居中。

边距:自动
使块元素的位置居中。该div正在居中,但这只是框本身居中,而不是框中的文本


text-align:center
将文本(和其他内联元素)居中放置在其容器中。

应用于p-tag style=“margin:auto;width:fit-content;”

应用于p-tag style=“margin:auto;width:fit-content;”“

将元素的内容居中放置,在元素的中心位置,不是它的内容。
text align
将元素的内容居中,在您的情况下,您是将元素居中,而不是将其内容居中。噢!我看错了东西的中心。谢谢,噢!我看错了东西的中心。谢谢