何时使用< p>与< br> [英] When to use <p> vs. <br>

查看:122
本文介绍了何时使用< p>与< br>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我环顾这个问题,但大部分的写作似乎有点老,所以我不确定是否关于这个话题的意见已经发展。



编辑:澄清问题,这里是我正在处理的情况。对于以下内容,您会使用< br> 的或< p> 的吗?在一个主页上的div):






欢迎来到主页。



查看我们的资料。



您真的应该。




现在,这些行在技术上不是'段落'。所以你会用< br> '来标记< p> 标记中的整个块s中间,或者对每一行使用单独的< p> 的s?

解决方案<他们提供两种不同的功能。

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



示例

 < p> Suspendisse sodales在felis sagittis hendrerit中。 Donec tempus laoreet 
est bibndum sollicitudin。 Etiam tristique convallis< br> rutrum。 Phasellus
id mi neque。 Vivamus gravida aliquam condimentum。< / p>

结果
<在felis sagittis hendrerit中悬挂苏打水。 Donec tempus laoreet
est bibndum sollicitudin。 Etiam tristique convallis
rutrum。 Phasellus
id mi neque。 Vivamus gravida aliquam condimentum。
$ b

更新



根据新的要求,I将亲自使用< p> 来实现间距并允许造型。如果将来您希望对这些零件中的一个进行设计,那么在块级别更容易。

  < p>欢迎来到主页。< / p> 

< p style =border:1px solid#00ff00;>查看我们的资料。< / p>

< p>您真的应该。< / p>


What's the verdict on when you should use another <p>...</p> instead of a <br /> tag? What's are the best practices for this kind of thing?

I looked around for this question, but most of the writing seems a bit old, so I'm not sure whether opinions about this topic have evolved since.

EDIT: to clarify the question, here is the situation that I am dealing with. Would you use <br>'s or <p>'s for the following content (imagine it's contained in a div on a homepage):


Welcome to the home page.

Check out our stuff.

You really should.


Now, these lines are not technically 'paragraphs'. So would you mark this up by surrounding the whole block in a <p> tag with <br>'s in between, or instead use separate <p>'s for each line?

解决方案

They serve two different functions.

<p> (paragraph) is a block element which is used to hold text. <br /> is used to force a line break within the <p> element.

Example

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

Result

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.

Update

Based on the new requirements, I would personally use <p> to achieve the spacing as well as allow for styling. If in the future you wish to style one of these parts, it will be much easier to do so at the block level.

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

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

<p>You really should.</p>

这篇关于何时使用&lt; p&gt;与&lt; br&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆