Html <p> 是块级元素还是内联级元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2789727/
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 <p> a block-level or inline-level element?
提问by Andor
I had a question when I came across the HTML 4.01 DTD:
In the strict DTD, a <p>
element is defined as
<!ELEMENT P - O (%inline;)* -- paragraph -->
but I thought that <p>
was a block-level element, and all (maybe almost all) user agents define <p>
as a block-level.
当我遇到 HTML 4.01 DTD 时,我有一个问题:在严格的 DTD 中,<p>
元素被定义为
<!ELEMENT P - O (%inline;)* -- paragraph -->
但我认为它<p>
是块级元素,并且所有(可能几乎所有)用户代理都定义<p>
为块级元素。
So is <p>
a block-level or inline-level element?
那么是<p>
块级元素还是内联级元素?
回答by nickf
It is a block level element. What that DTD is saying is that <p>
tags can only contain inline elements.
它是一个块级元素。DTD 所说的是<p>
标签只能包含行内元素。
回答by Sarfraz
Of course it is.
当然是这样。
The following are defined as block-level elements in XHTML 1.0:
以下在 XHTML 1.0 中被定义为块级元素:
* address - Address
* blockquote - Block quotation
* center - Centered block
* dir - Directory list
* div - Generic block-level container
* dl - Definition list
* fieldset - Form control group
* form - Interactive form
* h1 - Level-one heading
* h2 - Level-two heading
* h3 - Level-three heading
* h4 - Level-four heading
* h5 - Level-five heading
* h6 - Level-six heading
* hr - Horizontal rule
* isindex - Input prompt
* menu - Menu list
* noframes - Frames alternate content
* noscript - Alternate script content
* ol - Ordered list
* p - Paragraph
* pre - Preformatted text
* table - Table
* ul - Unordered list
The following elements may also be considered block-level elements since they may contain block-level elements:
以下元素也可以被视为块级元素,因为它们可能包含块级元素:
* dd - Definition description
* dt - Definition term
* frameset - Frameset
* li - List item
* tbody - Table body
* td - Table data cell
* tfoot - Table foot
* th - Table header cell
* thead - Table head
* tr - Table row
The following elements may be used as either block-level elements or inline elements. If used as inline elements (e.g., within another inline element or a p), these elements should not contain any block-level elements.
以下元素可用作块级元素或行内元素。如果用作内联元素(例如,在另一个内联元素或 ap 中),这些元素不应包含任何块级元素。
* applet - Java applet
* button - Button
* del - Deleted text
* iframe - Inline frame
* ins - Inserted text
* map - Image map
* object - Object
* script - Client-side script
回答by peristilo
The p element should not contain any other block element, although it is a block element itself. If you put block elements inside a p, you will, for example, have a hard time trying to apply css rules to those block elements.
p 元素不应包含任何其他块元素,尽管它本身就是一个块元素。例如,如果您将块元素放在 ap 中,您将很难尝试将 css 规则应用于这些块元素。
回答by Chase Higgins
It is block, but like any other block element the CSS display property can make it behave in a few ways, including inline or inline-block.
它是块元素,但与任何其他块元素一样,CSS display 属性可以使其以多种方式运行,包括 inline 或 inline-block。