何时使用<p> vs. <br>

Wil*_*itz 66 html html5

你何时应该使用另一个<p>...</p>而不是<br />标签的判决是什么?这种事情的最佳做法是什么?

我环顾四周寻找这个问题,但大部分写作似乎都有些陈旧,所以我不确定自那时起对这个话题的看法是否有所改变.

编辑:澄清问题,这是我正在处理的情况.你会使用<br>'s或<p>'s作为以下内容(想象它包含在主页上的div中):


欢迎来到主页.

看看我们的东西.

你真的应该.


现在,这些线在技术上不是"段落".那么你是否会通过在一个<p>带有<br>'s'的标签中包围整个块来标记这一点,或者<p>为每一行使用单独的?

Ker*_*mit 64

它们有两种不同的功能.

<p>(段落)是用于保存文本的块元素.<br />用于强制<p>元素内的换行符.

<p>Suspendisse sodales odio in felis sagittis hendrerit. Donec tempus laoreet
est bibendum sollicitudin. Etiam tristique convallis<br />rutrum. Phasellus 
id mi neque. Vivamus gravida aliquam condimentum.</p>
Run Code Online (Sandbox Code Playgroud)

结果

Suspendisse sodales odio in felis sagittis hendrerit.Donec tempus laoreet est bibendum sollicitudin.Etiam tristique convallis
rutrum.Phasellus id mi neque.Vivamus gravida aliquam condimentum.

更新

根据新的要求,我个人会<p>用来实现间距以及允许造型.如果将来你希望设置这些部件中的一个,那么在块级别上这样做会容易得多.

<p>Welcome to the home page.</p>

<p style="border: 1px solid #00ff00;">Check out our stuff.</p>

<p>You really should.</p>
Run Code Online (Sandbox Code Playgroud)


Eri*_*ves 8

<p>当您需要将两个信息流分解为单独的想法时,您希望使用该标记.

<p> Now is the time for all good men to come to the aid of their country. </p>

<p>The quick brown fox jumped over the lazy sleeping dog.</p>
Run Code Online (Sandbox Code Playgroud)

<br/>标签被用作网页的文本流中强制断行.当您希望文本在下一行继续时使用它,例如诗歌.

<p>  Now is the time for all good men to come to the aid of their country. <br/>
The quick brown fox jumped over the lazy sleeping dog. </p>
Run Code Online (Sandbox Code Playgroud)

资源