为什么是<center>标签在 HTML 中已弃用?

2022-01-18 00:00:00 tags html deprecated center

我只是好奇为什么 HTML 中的 <center> 标签被弃用了.

I am just curious as to why the <center> tag in HTML was deprecated.

<center> 是一种通过将容器封装在 <center> 标记中来快速居中对齐文本和图像块的简单方法,而我现在真的找不到更简单的方法了.

The <center> was a simple way of quickly center-aligning blocks of text and images by encapsulating the container in a <center> tag, and I really cannot find any simpler way on how to do it now.

任何人都知道如何将东西"(不是 margin-left:auto; margin-right:auto; 和宽度的东西)居中的任何简单方法,取代 <中心> ?还有,为什么它被弃用了?

Anyone know of any simple way on how to center "stuff" (not the margin-left:auto; margin-right:auto; and width thing), something that replaces <center> ? And also, why was it deprecated?

推荐答案

<center> 元素已被弃用,因为它定义了其内容的 表示——它确实不描述其内容.

The <center> element was deprecated because it defines the presentation of its contents — it does not describe its contents.

居中的一种方法是将元素的margin-leftmargin-right属性设置为auto,然后设置父元素的 text-align 属性到 center.这保证了元素将在所有现代浏览器中居中.

One method of centering is to set the margin-left and margin-right properties of the element to auto, and then set the parent element’s text-align property to center. This guarantees that the element will be centered in all modern browsers.

相关文章