Apply a class to a br tag?

后端 未结 10 1437
感情败类
感情败类 2021-02-06 21:10

Is the following valid HTML?


As an HTML element I can\'t see why it wouldn\'t be, but I don\'t think I\'ve eve

相关标签:
10条回答
  • 2021-02-06 21:35

    Yes, is valid.

    Specification tells that br accepts global and event attributes, 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 DOCTYPE lets you, you should not use it anymore.

    0 讨论(0)
  • 2021-02-06 21:41

    It does come handy when you want to omit the linebreak.e.g in a Headline when having a responsive layout and certain breakpoints.

    0 讨论(0)
  • 2021-02-06 21:51

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

    0 讨论(0)
  • 2021-02-06 21:52

    Yes, it's valid statement. you could use something like.

    <br style="height: 100px; margin-top: 10000px;">
    

    But instead using div element is recommended.

    0 讨论(0)
  • 2021-02-06 21:53

    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:

    hr.something:after  { content: "Some text"  }
    
    0 讨论(0)
  • 2021-02-06 21:54

    Yes you can, from the w3c specification : http://dev.w3.org/html5/markup/br.html

    <br> element can make use of global attributes, and class is one of them.

    0 讨论(0)
提交回复
热议问题