Should I use the

tag in markup?

2019-01-17 22:46发布

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

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

11条回答
ゆ 、 Hurt°
2楼-- · 2019-01-17 23:24

The <p> tag defines a paragraph. There's no reason for an empty paragraph.

查看更多
ら.Afraid
3楼-- · 2019-01-17 23:24

For any practical purpose you dont need to add the </p> into your markup. But if there is string XHTML adheration requirement, then you would probably need to close all your markup tags, including <p>. Some XHTML analyzer would report this as an error.

查看更多
Anthone
4楼-- · 2019-01-17 23:28

The HTML DTD does not prohibit you from using an empty <p> (a <p> element may contain PCDATA including the empty string) , but it doesn't make much sense to have an empty paragraph.

查看更多
姐就是有狂的资本
5楼-- · 2019-01-17 23:35

Modern HTML semantics are:

  • 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.

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.

查看更多
Rolldiameter
6楼-- · 2019-01-17 23:36

Paragraph is a paragraph, break is a break.

A <p> is like a regular Return in Office Word.
A <br> is like a soft return Shift + Return in Office Word.

the first one sets all paragraph settings/styles, the second one barely breaks a line of text.

Yes <p> elements are encouraged, and won't get deprecated any time soon.

查看更多
劫难
7楼-- · 2019-01-17 23:37

Use it for what? All tags have their own little purpose in life, but no tag should be used for everything. Find out what you are trying to make, and then decide on what tag fits that idea best:

If it is a paragraph of text, or at least a few lines, then wrap it in <p></p>

If you need a line break between two lines of text, then use <br />

If you need to wrap many other elements in one element, then use the <div></div> tags.

查看更多
登录 后发表回答