简体   繁体   English

是<p>块级或内联级元素?

[英]Is <p> a block-level or inline-level element?

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>是块级元素还是内联级元素?

It is a block level element.它是一个块级元素。 What that DTD is saying is that <p> tags can only contain inline elements. DTD 的意思是<p>标签只能包含行内元素。

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 (eg, within another inline element or ap), 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

More Info Here 更多信息在这里

The p element should not contain any other block element, although it is a block element itself. p 元素不应包含任何其他块元素,尽管它本身就是一个块元素。 If you put block elements inside ap, you will, for example, have a hard time trying to apply css rules to those block elements.例如,如果您将块元素放在 ap 中,您将很难尝试将 css 规则应用于这些块元素。

它是块元素,但与任何其他块元素一样,CSS display 属性可以使其以多种方式运行,包括 inline 或 inline-block。

Block level块级

Source: here来源:这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM