开发者社区> 问答> 正文

问问 CSS的float属性

css中设置了float:left/right属性的元素到底有没有脱离标准文档流,看了网上的一些说法,有说完全脱离,有说半脱离,到底是个神马情况,求大神给个指导,谢谢!

展开
收起
杨冬芳 2016-06-08 17:26:55 2162 0
1 条回答
写回答
取消 提交回答
  • IT从业

    screenshot

    w3c上的规范 https://www.w3.org/TR/CSS1/#floating-elements

    Using the 'float' property, an element can be declared to be outside the normal flow of elements and is then formatted as a block-level element.

    那个”半脱离“可能的意思是和z-index或者是浮动元素提升半个层级有关吧,或者就是自己发明的概念,以下是我个人理解

    可以参看这篇文章
    stacking and float

    其中有句话

    For floating blocks the stacking order is a bit different. Floating blocks are placed between non-positioned blocks and positioned blocks:

    意思就是浮动块在stacking context中的顺序是比较特殊的,是介于未定位的块(也就是普通文档流)和已经定位块之间,也就是其他人所说的提升半个层级。

    关于stacking context的概念,大家可以参考The Stacking Context

    关于z-index, 参考这篇 Adding z-index

    2019-07-17 19:32:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
零基础CSS入门教程 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载