我很好奇为什么不推荐使用 HTML 中的 <center>
标记。
<center>
是一种通过将容器封装在 <center>
标签中来快速居中对齐文本和图像块的简单方法,我真的找不到任何更简单的方法来实现它现在。
任何人都知道如何将“东西”(不是 margin-left:auto; margin-right:auto;
和宽度的东西)居中的任何简单方法,取代 <center>
的东西?而且,为什么它被弃用了?
原文由 Andreas Grech 发布,翻译遵循 CC BY-SA 4.0 许可协议
<center>
元素已弃用,因为它定义了其内容的 呈现 方式——它不描述其内容。One method of centering is to set the
margin-left
andmargin-right
properties of the element toauto
, and then set the parent element’stext-align
property到center
。这保证了该元素将在所有现代浏览器中居中。