Html 将类应用于 br 标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16944403/
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
Apply a class to a br tag?
提问by Evanss
Is the following valid HTML?
以下是有效的 HTML 吗?
<br class="something">
As an HTML element I can't see why it wouldn't be, but I don't think I've ever seen it in use.
作为一个 HTML 元素,我不明白为什么它不会,但我认为我从未见过它在使用中。
采纳答案by Artur Udod
One application I can think off is adding using it with pseudo-elements, such as :before
or :after
, for instance adding some text beneath a horizotal line:
我可以想到的一个应用程序是将它与伪元素一起使用,例如:before
or :after
,例如在水平线下方添加一些文本:
hr.something:after { content: "Some text" }
回答by Quentin
Yes.
是的。
See the specification.
请参阅规范。
The class
attribute applies to "HTML Elements" (which includes br
elements).
该class
属性适用于“HTML 元素”(包括br
元素)。
回答by Jorge Fuentes González
Yes, is valid.
是的,有效。
Specificationtells that br
accepts globaland eventattributes, and class
is a global one.
Note that if you target HTML4 and below, there's an specific attribute for br
named clear
, which defines where to put the new line, as stated here, but now is deprecated and unless your DOCTYPElets you, you should not use it anymore.
请注意,如果您的目标是 HTML4 及以下,则br
named有一个特定属性clear
,它定义了新行的放置位置,如此处所述,但现在已弃用,除非您的DOCTYPE允许,否则不应再使用它。
回答by Vivek T
Yes, it's valid statement. you could use something like.
是的,这是有效的声明。你可以使用类似的东西。
<br style="height: 100px; margin-top: 10000px;">
But instead using div element is recommended.
但建议使用 div 元素。
回答by Jukka K. Korpela
It is valid in HTML 4.01, because the class
attribute is allowed for the br
element. It is also valid in HTML5 in HTML serialization, because the class
attribute is allowed for all elements. It is not valid XHTML without a matching </br>
.
它在 HTML 4.01 中有效,因为元素class
允许使用该属性。它在 HTML 序列化中的 HTML5 中也有效,因为该属性允许用于所有元素。如果没有匹配的.br
class
</br>
回答by Laurent S.
Yes you can, from the w3c specification : http://dev.w3.org/html5/markup/br.html
是的,你可以,从 w3c 规范:http: //dev.w3.org/html5/markup/br.html
<br>
element can make use of global attributes, and class
is one of them.
<br>
element 可以使用全局属性,并且class
是其中之一。
回答by John Topley
Yes, you can add a class
attribute to a <br>
element. id
as well if you want.
是的,您可以class
向<br>
元素添加属性。id
如果你愿意,也可以。
回答by ThatBlairGuy
Sure, it's valid. A useful example would be if you wanted to visually add a little space after a line-break, without ending the paragraph. Or perhaps apply a background image. All sorts of styling options.
当然,它是有效的。一个有用的例子是,如果您想在换行符后在视觉上添加一点空间,而不是结束段落。或者也许应用背景图像。各种造型选择。
回答by inquisitive
a br
tag doesn't produce a CSS box and hence little can be done with it.
一个br
标签不会产生CSS框,因此很少可以用它来完成。
Only practical case is clear
. i believe drupal used it at some time. interestingly CSS 1 spec. refrained from doing anything to br. http://www.w3.org/TR/REC-CSS1/#br-elements. no doubt applying some css on it doesn't invalidate the code but will cause little effect.
唯一的实际情况是clear
. 我相信 Drupal 曾经使用过它。有趣的是 CSS 1 规范。克制自己做任何事。http://www.w3.org/TR/REC-CSS1/#br-elements。毫无疑问,在其上应用一些 css 不会使代码无效,但影响很小。
this https://stackoverflow.com/a/899359/1043824is a good discussion on the topic.
这个https://stackoverflow.com/a/899359/1043824是关于这个话题的一个很好的讨论。
回答by Bustl3r
It does come handy when you want to omit the linebreak.e.g in a Headline when having a responsive layout and certain breakpoints.
当您想要在具有响应式布局和某些断点时省略标题中的 linebreak.eg 时,它确实会派上用场。