Html 现在使用 <br /> 标签已经过时了吗?如果是这样,我应该用什么代替?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14197709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it out of date to use <br /> tag nowadays? If so, what should I use instead?
提问by Foo
Is it out of date to use
tag nowadays? If so, what should I use instead?
For new line, I coding like this. This is not supposed to do these days?
现在使用标签已经过时了吗?如果是这样,我应该用什么代替?
对于新行,我是这样编码的。这几天不应该做吗?
<br />
<br />
<br />
<br />
回答by Sean
<br />
is meant to be used as to represent a break in said content, a common example would be an address:
<br />
用于表示所述内容的中断,一个常见的例子是地址:
<p>
20 street name<br />
City Name<br />
etc.
</p>
As you can see in the above example, the address is all one group of content, the breaks are only for presentational purposes.
正如您在上面的示例中看到的,地址都是一组内容,中断仅用于演示目的。
In short: <p>
tags should be used to seperate content into blocks, and the <br />
tag should be used for any breaks needed in that content (for presentational purposes, as in the example above)
简而言之:<p>
标签应该用于将内容分成块,<br />
标签应该用于该内容中需要的任何中断(出于演示目的,如上例所示)
The <br />
tag is perfectly valid, it's in the current HTML5 spec too.
该<br />
标签完全有效,它也在当前的 HTML5 规范中。
回答by cowls
HTML 5 only requires <br>
however <br/>
is still fine.
HTML 5 只需要<br>
但是<br/>
仍然可以。
If you were using something like XHTML you would want that to be <br />
anyway..
如果你使用的是像 XHTML 这样的东西,你<br />
无论如何都希望它是..
This question will probably tell you everything you need to know: HTML 5: Is it <br>, <br/>, or <br />?
这个问题可能会告诉你你需要知道的一切:HTML 5:它是 <br>、<br/> 还是 <br />?
回答by Quentin
(From the original question, before it was edited): The "line break end tag" should only ever have been used in XHTML served with an XML content-type (i.e. almost never) and even then you could still use <br />
.
(来自原始问题,在编辑之前):“换行结束标记”应该只在使用 XML 内容类型的 XHTML 中使用过(即几乎从不),即使这样,您仍然可以使用<br />
.
Dealing with the edited question alone:
单独处理编辑过的问题:
If you want a line break then use <br>
(or <br />
in XHTML). HTML 5 also permits <br />
but this is just syntactic sugar for the XML addicted and bad syntax highlighters.
如果您想要换行,请使用<br>
(或<br />
在 XHTML 中)。HTML 5 也允许,<br />
但这只是 XML 上瘾和糟糕的语法高亮器的语法糖。
The line break element isn't out of date, but like any other element, it should only be used in appropriate places. There aren't many places when a line break is appropriate, the most common ones that prince to mind are postal addresses and poetry. In most cases a <p>
is more suitable. In places where multiple sequential line breaks appear, a stylesheet that adds padding or margins is often the right choice.
换行元素并没有过时,但与任何其他元素一样,它应该只在适当的地方使用。适合换行的地方并不多,最常见的是邮政地址和诗歌。在大多数情况下,a<p>
更合适。在出现多个连续换行符的地方,添加填充或边距的样式表通常是正确的选择。
回答by Riskbreaker
I'm going to answer the question differently:
我将以不同的方式回答这个问题:
You can use <br />
but to answer the question the way I think you are asking... is that you can have the <p>
or <div>
control the spacing using padding element. so instead of adding <br />
just make padding on the p or div element. But as people mention <p>
is the way to go :)
您可以使用<br />
但以我认为您要问的方式回答这个问题......是您可以使用填充元素来控制<p>
或<div>
控制间距。所以不要<br />
在 p 或 div 元素上添加填充。但正如人们所提到<p>
的那样:)