如果你在设计一个简单的网页,那么明显区别不大,但是了解这两者的基本区别是非常有必要的。由于我们只关心文本,这些元素没有单独的含义。
HTML
- 示例:以下代码早先在 HTML 4 和旧版本中用于将文本居中对齐。
html
GeeksforGeeks
HTML center Tag
GeeksforGeeks: A computer science portal for Geeks.
html
text-align: center property GeeksforGeeks
CSS "text-align:center;" Property
GeeksforGeeks: A computer science portal for Geeks.
- 输出:
CSS“文本对齐:居中;”属性:是一个CSS属性,用于将文本居中对齐,可以在很多组件中使用,包括表格、按钮等。
- 示例: “text-align:center”属性的实现如下:
html
text-align: center property GeeksforGeeks
CSS "text-align:center;" Property
GeeksforGeeks: A computer science portal for Geeks.
- 输出:
您可以注意到两个输出是相同的,但在 HTML5 代码的情况下,我们使用内联 CSS 将我们的文本与中心对齐。在之前的 HTML4 和旧版本代码中,我们专门使用了
HTML
HTML |
CSS “text-align: center;” Property |
---|---|
HTML |
CSS “text-align: center;” property is an inline element. |
It is best to attach it to a section of a web page. | It is best to attach it to a small section of a line in a web page. |
HTML 5 does not support the center tag, and also the upcoming versions of HTML would not support it. | HTML 5 supports the “text-align: center;” property, and also the upcoming versions of HTML will support it. |
This tag should use to wrap a section, for centering that section. | This tag should use to wrap any specific word that you want to center on your webpage. |