做<span>具有“位置:绝对"的元素表现得像块级元素? [英] Do <span> elements with "position: absolute;" behave as block-level elements?

查看:23
本文介绍了做<span>具有“位置:绝对"的元素表现得像块级元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

元素是否具有 position: absolute; 能够具有高度、宽度、填充等,而无需将其更改为 display: block;inline-block;?

Are <span> elements with position: absolute; able to have a height, width, padding, etc. without changing it to display: block; or inline-block;?

它似乎有效,但是对于具有 position 的 元素,所有浏览器都可以省略 display: block/inline-block: 绝对;?

It seems to work, but is it ok with all browsers to omit display: block/inline-block for a <span> element with position: absolute;?

推荐答案

简短回答:是的.

长答案:见 http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo(或 SLaks 的回答).

Long answer: see http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo (or SLaks's answer).

但是,这个变化只涉及元素的视觉显示模型.CSS 不能影响 HTML 元素的内容模型因为 CSS 仅在文档​​被解析为 DOM 树后才应用.所以 span 元素永远不能有 pdiv 子元素,无论应用哪种样式.

Hovewer, this change refers only to the visual display model of the element. The CSS can't affect the content model of the HTML element since CSS is applied only after the document is parsed into DOM tree. So span element can never have p or div children, no matter which styles are applied to it.

这篇关于做&lt;span&gt;具有“位置:绝对"的元素表现得像块级元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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