Html <hr> 和 <br> 是内联元素还是块元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1369234/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:47:49  来源:igfitidea点击:

Are <hr> and <br> inline or block elements?

html

提问by Svish

My guess is that <br>might be inline and that <hr>might be block. But I don't really have a clue...

我的猜测是这<br>可能是内联的,也<hr>可能是阻塞的。但是我真的一点头绪都没有……

回答by Gumbo

The HRelement is defined to be element of block. It's also being displayed in its own line like any other block element. Thus HRis a block element.

HR元素被定义为block 的元素。它也像任何其他块元素一样显示在自己的行中。因此HR是一个块元素

The BRelement is defined to be element of specialand that is defined to be inline. It's also not being displayed in its own like like a block element, but just creating a line break. Thus BRis an inline element.

BR元素被定义为特殊元素,并且被定义为内联元素。它也不会像块元素一样单独显示,而只是创建一个换行符。因此BR是一个内联元素

回答by Dan Diplo

According to the HTML 4.0 Strict DTD:

根据HTML 4.0 Strict DTD

<HR />is a block-level element and <BR />is an inline element.

<HR />是一个块级元素并且<BR />是一个内联元素。

All the block-level elements are defined in the DTD thus:

所有块级元素都在 DTD 中定义,因此:

<!ENTITY % block
     "P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
      BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">


<!ENTITY % heading "H1|H2|H3|H4|H5|H6">

<!ENTITY % list "UL | OL">

<!ENTITY % preformatted "PRE">

The rest are inline by default. Of course, a BR does force a line-break so acts similar to a block level element, but that doesn't mean it is.

其余的默认是内联的。当然,BR 确实会强制换行,因此其行为类似于块级元素,但这并不意味着它是。

回答by Dave Kanter

Years later...HR itself is a part of HTML5 but with more emphasis on it being a semantic and not layout element. So keep using it but style it up with CSS.

多年以后...... HR 本身是 HTML5 的一部分,但更强调它是一个语义而不是布局元素。所以继续使用它,但用 CSS 来设计它。

回答by HTMLer

HR ELEMENT Deprecated element: It is not advised to use and cannot bo used under the declaration of strict conformance. Block element: There are vertical space before and after the element. Empty element: There is only one tag:

HR ELEMENT 不推荐使用的元素:不建议使用,也不能在严格符合声明下使用。块元素:元素前后有垂直空间。空元素:只有一个标签:



. 此元素不包含结束标记或文本正文。

BR ELEMENT Inline element: It is put where it needs to be, within the text body. Tehre is no vertical space before and after it. Empty element.

BR ELEMENT 内联元素:它被放置在文本正文中需要的位置。Tehre 前后没有垂直空间。空元素。

回答by richardtallent

BR is an inline element, and has been deprecated in XHTML 2 in favor of LINE. (All academic at this point, of course...)

BR 是一个内联元素,在 XHTML 2 中已被弃用,取而代之的是 LINE。(当然,此时所有的学术都...)

HR wasa block element, but was deprecated in HTML 4.01 and is not part of the XHTML 1.0 Strict DTD.

HR一个块元素,但在 HTML 4.01 中被弃用,并且不是 XHTML 1.0 Strict DTD 的一部分。