问题描述
我知道把一个块元素放在内联元素中是错误的,但是下面的内容呢?
想象一下这个有效的标记:
< div>< p>这是一个段落< / p>< / div>
现在添加此CSS:
div {
display:inline;
}
这会创建一个内联元素包含块元素的情况
页面元素是否仍然有效?
如何以及何时执行我们判断HTML是否有效 - 在应用CSS规则之前或之后?
UPDATE:将块级元素放置在链接标签内是完全有效的,例如:
< a href =#>
< h1>标题< / h1>
< p>段落。< / p>
< / a>
这实际上是非常有用的,如果你想要一个大块的HTML是一个链接。 >
从:
做你想做的事。显然,在CSS中指定了行为,虽然它是否涵盖所有情况,或在今天的浏览器中实现一致是不清楚的。
I know it's wrong to put a block element inside an inline element, but what about the following?
Imagine this valid markup:
<div><p>This is a paragraph</p></div>
Now add this CSS:
div {
display:inline;
}
This creates a situation where an inline element contains a block element (The div becomes inline and the p is block by default)
Are the page elements still valid?
How and when do we judge if the HTML is valid - before or after the CSS rules are applied?
UPDATE: I've since learned that in HTML5 it is perfectly valid to put block level elements inside link tags eg:
<a href="#">
<h1>Heading</h1>
<p>Paragraph.</p>
</a>
This is actually really useful if you want a large block of HTML to be a link.
From the CSS 2.1 Spec:
Make of that what you will. Clearly the behaviour is specified in CSS, although whether it covers all cases, or is implemented consistently across today's browsers is unclear.
这篇关于如果块元素包含另一个块元素,那么将它更改为与CSS内联是错误的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!