我应该使用 <p/>标记中的标记?

2022-01-18 00:00:00 tags layout html markup

当需要更高级的东西时,我总是使用 <br/><div/> 标签.

I have always used either <br /> or a <div/> tag when something more advanced is necessary.

是否仍鼓励使用 <p/> 标签?

Is use of the <p/> tag still encouraged?

推荐答案

现代 HTML 语义有:

Modern HTML semantics are:

  • 使用 <p></p> 在文档中包含一段文本.
  • 使用 <br/> 表示段落内的换行符(即没有段落块边距或填充的新行).
  • 使用 <div></div> 包含一块恰好具有块布局的应用程序 UI.
  • Use <p></p> to contain a paragraph of text in a document.
  • Use <br /> to indicate a line break inside a paragraph (i.e. a new line without the paragraph block margins or padding).
  • Use <div></div> to contain a piece of application UI that happens to have block layout.

不要单独使用 <div/><p/>,这些标签是用来包含内容的.它们似乎只是作为段落分隔符起作用,因为当浏览器看到它们时,它会有用地"关闭当前块标签,然后再打开空标签.

Don't use <div /> or <p /> on its own, those tags are meant to contain content. They appear to work as paragraph breaks only because when the browser sees them, it "helpfully" closes the current block tag before opening the empty one.

相关文章