在HTML5中,< div>从技术上讲,它是一个块级元素,但表现为一个内联元素。这是一种特殊的“混合”元素吗? [英] In HTML5, a <div> is technically a block-level element, but behaves as an in-line element. Is this a special 'hybrid' element?

查看:177
本文介绍了在HTML5中,< div>从技术上讲,它是一个块级元素,但表现为一个内联元素。这是一种特殊的“混合”元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

W3Schools定义的块级元素在元素之前和之后有一个换行符,例如 p,h1,等。非嵌套的内联元素要么自行开始(不是如果嵌套,则保持在同一行。

A block level element as defined by the W3Schools has having a line break before and after the element, such as p, h1, etc. Non nested inline elements either start on their own line (no line break) or remain on the same line if nested.

虽然 span 行为正常(以及所有其他内联元素)。 Div 永远不会像块元素一样创建换行符,但只会在div元素开头的新行上开始。

While span behaves normally (as well as all other inline elements). Div never creates line breaks like block elements all do, but only starts on a new line at the opening of the div element.

也许我错过了一些东西,因为每个人都在谈论 DIV 是块级别,但它的行为就像一个内联元素,因为它启动了一个新的如果没有嵌套,则不会创建换行符,但完全相反,当 div 与另一个 div 嵌套时,它只会创建一个新行。

Perhaps I'm missing something since everyone talks about DIV being block level, but it behaves like an inline element in that it starts a new line if not nested, doesn't create line breaks, but acts like something else entirely that when a div is nested with another div it just creates a new line.

DIV 是唯一的混合元素吗?我错过了一些更基本的东西吗?

Is DIV the only "hybrid" element like this? Am I missing something more fundamental?

推荐答案

没有元素会创建换行符。您只是看到不同默认样式的效果,这些样式具有不同的 margin padding 值。默认样式因浏览器而异,但通常看起来像HTML 4规范中包含的[非常过时]参考样式表: http://www.w3.org/TR/CSS2/sample.html

No elements create line breaks. You're merely seeing the effects of different default styles, which have different margin and padding values. The default styles vary per browser, but often look something like the [very dated] reference stylesheet included with the HTML 4 spec: http://www.w3.org/TR/CSS2/sample.html

这篇关于在HTML5中,< div>从技术上讲,它是一个块级元素,但表现为一个内联元素。这是一种特殊的“混合”元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆