HTML5中的内联级元素内是否允许块级元素? [英] Are block-level elements allowed inside inline-level elements in HTML5?

查看:104
本文介绍了HTML5中的内联级元素内是否允许块级元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如



< a href =#>< h1>标题< ; / h1>< / a> 在HTML5中有效吗?

解决方案

是的,你有什么写在HTML5中有效,但它不是所有内联元素,我认为它只适用于< a> ..



参考: HTML5中的块级链接



提示:如果使用此设置< a> display:block; 或者可能存在意外的视觉样式效果:来源:测试用例



更新:



其他内联块组合被禁止,其中默认样式可能会导致混淆 - 解释是h ere


默认样式可能导致混淆的情况



某些元素的默认样式为
,或者某些元素使得某些
组合可能导致
混淆。在没有这个问题的情况下,如果这些商品具有相同的
替代品,则不允许出现
混淆组合。

例如,div元素的价格为
阻止框和span元素作为
内联框。在
中放置一个块框不需要
混淆;因为嵌套只是
div元素,或者嵌套只是跨越
元素,或者嵌套元素
在div元素内所有都提供相同的
目的,因为嵌套div元素
a span元素
,但只有后者
包含内嵌框中的块框,
后者组合不允许。



For an example

Is <a href="#"><h1>Heading</h1></a> valid in HTML5?

解决方案

yes what you've written is valid in HTML5, but it's not all inline elements, I think it's just <a> 's it applies to..

Reference: "Block-level" links in HTML5

Tip: if using this set the <a> to display: block; or there may be unintended visual styling results : Source: Test Case

Update:

It is "disallowed" for other "block in inline" combinations where "default styles are likely to lead to confusion" - explanation is here:

Cases where the default styles are likely to lead to confusion

Certain elements have default styles or behaviors that make certain combinations likely to lead to confusion. Where these have equivalent alternatives without this problem, the confusing combinations are disallowed.

For example, div elements are rendered as block boxes, and span elements as inline boxes. Putting a block box in an inline box is unnecessarily confusing; since either nesting just div elements, or nesting just span elements, or nesting span elements inside div elements all serve the same purpose as nesting a div element in a span element, but only the latter involves a block box in an inline box, the latter combination is disallowed.

这篇关于HTML5中的内联级元素内是否允许块级元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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