我只是好奇为什么HTML中的<center>标记被弃用了。
<center>是一种通过将容器封装在<center>标签中来快速居中对齐文本和图像块的简单方法,现在我真的找不到任何更简单的方法了。
有人知道任何简单的方法如何居中“东西”(不是左边距:auto;margin-right:汽车;width),替换<center> ?还有,为什么它被弃用了?
我只是好奇为什么HTML中的<center>标记被弃用了。
<center>是一种通过将容器封装在<center>标签中来快速居中对齐文本和图像块的简单方法,现在我真的找不到任何更简单的方法了。
有人知道任何简单的方法如何居中“东西”(不是左边距:auto;margin-right:汽车;width),替换<center> ?还有,为什么它被弃用了?
当前回答
我有时仍然使用<center>标签,因为CSS中的任何东西都不能很好地工作。尝试使用<div>技巧而失败的例子:
<div style="text-align: center;">This div is centered, but it's a simple example.</div> <br /> <div style="text-align: center;"><table border="1"><tr><td><div style="text-align: center;"> didn't center correctly.</td></tr></table></div> <br /> <div style="text-align: center;margin-left:auto;margin-right:auto"><table border="1"><tr><td><div style="text-align: center;margin-left:auto;margin-right:auto"> still didn't center either</td></tr></table></div> <br /> <center><table border="1"><tr><td>Actually Centered with <center> tag</td></tr></table></center>
<center> gets results. To use CSS instead, you sometimes have to put CSS in several places and mess with it to get it to center right. To answer your question, CSS has become a religion with believers and followers who shunned <center> <b> <i> <u> as blasphemy, unholy, and much too simple for the sake of their own job security. And if they try to take your <table> away from you, ask them what the CSS equivalent of the colspan or rowspan attribute is. It is not the abstract or bookish truth, but the lived truth that counts. -- Zen
其他回答
据W3Schools.com报道,
中心元素在HTML 4.01中已弃用,并且在XHTML 1.0 Strict DTD中不受支持。
HTML 4.01规范给出了弃用标记的原因:
CENTER元素完全等价于将align属性设置为“CENTER”来指定DIV元素。
发人深思:文本-语音合成器使用<center>会做什么?
我有时仍然使用<center>标签,因为CSS中的任何东西都不能很好地工作。尝试使用<div>技巧而失败的例子:
<div style="text-align: center;">This div is centered, but it's a simple example.</div> <br /> <div style="text-align: center;"><table border="1"><tr><td><div style="text-align: center;"> didn't center correctly.</td></tr></table></div> <br /> <div style="text-align: center;margin-left:auto;margin-right:auto"><table border="1"><tr><td><div style="text-align: center;margin-left:auto;margin-right:auto"> still didn't center either</td></tr></table></div> <br /> <center><table border="1"><tr><td>Actually Centered with <center> tag</td></tr></table></center>
<center> gets results. To use CSS instead, you sometimes have to put CSS in several places and mess with it to get it to center right. To answer your question, CSS has become a religion with believers and followers who shunned <center> <b> <i> <u> as blasphemy, unholy, and much too simple for the sake of their own job security. And if they try to take your <table> away from you, ask them what the CSS equivalent of the colspan or rowspan attribute is. It is not the abstract or bookish truth, but the lived truth that counts. -- Zen
如果您愿意,您仍然可以将其用于XHTML 1.0 Transitional和HTML 4.01 Transitional。唯一的另一种方法(在我看来最好的方法)是使用边缘:
<div style="width:200px;margin:auto;">
<p>Hello World</p>
</div>
HTML应该定义元素,而不是控制它的表示。
HTML的目的是结构化数据,而不是控制布局。CSS用于控制布局。您还会发现许多设计人员出于同样的原因不愿意使用<table>进行布局。