我只是好奇为什么HTML中的<center>标记被弃用了。
<center>是一种通过将容器封装在<center>标签中来快速居中对齐文本和图像块的简单方法,现在我真的找不到任何更简单的方法了。
有人知道任何简单的方法如何居中“东西”(不是左边距:auto;margin-right:汽车;width),替换<center> ?还有,为什么它被弃用了?
我只是好奇为什么HTML中的<center>标记被弃用了。
<center>是一种通过将容器封装在<center>标签中来快速居中对齐文本和图像块的简单方法,现在我真的找不到任何更简单的方法了。
有人知道任何简单的方法如何居中“东西”(不是左边距:auto;margin-right:汽车;width),替换<center> ?还有,为什么它被弃用了?
当前回答
标记,即HTML标记,表示含义和结构,而不是外观。它在早期版本的HTML中被严重混淆,但现在标准的人们正试图清理它。
让标签控制外观的一个问题是,您的页面不能很好地使用针对残疾人的设备,例如屏幕阅读器。这也会导致在你的文本中有很多很多的标签,这些标签不能帮助阐明意思,而是用不同层次的信息使它变得混乱。
因此,CSS被认为是将格式/显示转移到不同的语言,这与文本是分开的,可以很容易地保持这种方式。其中,这允许切换样式表来更改Web页面的外观,而不涉及其他标记。而且能够做到在一个膨胀的foop很多页。
CSS提供的工具并不总是很优雅,我站在你这边。例如,没有办法进行有效的垂直定心。水平居中,如果它不仅仅是文本符合文本对齐,也不会好到哪里去。
你可以选择简单、有效、混乱,也可以选择干净、优雅、繁琐。我不明白为什么Web开发人员要忍受这种混乱,但我猜他们很高兴至少有机会完成他们的工作。
其他回答
发人深思:文本-语音合成器使用<center>会做什么?
HTML的目的是结构化数据,而不是控制布局。CSS用于控制布局。您还会发现许多设计人员出于同样的原因不愿意使用<table>进行布局。
您可以将此添加到您的css中,并使用<div class="center"></div>
.center{
text-align: center;
margin: auto;
justify-content: center;
display: flex;
}
或者如果你想保留<center></center>,并为它被删除做好准备,将其添加到你的CSS中
center{
text-align: center;
margin: auto;
justify-content: center;
display: flex;
}
我有时仍然使用<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
Center在HTML中很受欢迎,因为它是一种快速创建工作原型的方法,而无需在工作的早期阶段设置CSS。当然,与使用CSS为各种元素创建全局中心相比,在完成的页面上使用中心变得很麻烦。因此,center将永远在网络上有一席之地,仍然有一些老派论坛在他们的帖子中以这种格式为中心的元素。
换句话说,喜欢中心标签,因为当你需要它的时候,它很可爱,很高效!
PS: Marquee也是一个经典的HTML标签,它仍然存在,看起来非常棒^__^