好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

DOM中关于脱离文档流的几种情况分析_html/css_WEB-ITnose

所谓的文档流,指的是元素排版布局过程中,元素会自动从左往右,从上往下的流式排列。并最终窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素。脱离文档流即是元素打乱了这个排列,或是从排版中拿走。

  当前所知的脱离文档流的方式有两种:浮动和定位。

  

a.定位属性positon

  先看一下定位。看一段对定位各个字段的描述,有助于理解

值 描述 absolute

生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位。

元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定。

fixed

生成绝对定位的元素,相对于浏览器窗口进行定位。

元素的位置通过 "left", "top", "right" 以及 "bottom" 属性进行规定。

relative

生成相对定位的元素,相对于其正常位置进行定位。

因此,"left:20" 会向元素的 LEFT 位置添加 20 像素。

static 默认值。没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明)。 inherit 规定应该从父元素继承 position 属性的值。

  position的值为absolute、fixed的元素脱离文档流,static、relative没有脱离文档流

  position定位测试例子(为了不影响定位效果,文字都放在了最后)

                    -->           *{      margin: 0;      padding: 0;      text-align: right;      color: #FFF;    }    #container{      position: absolute;      left: 20px;      margin-top: 10px;      width: 600px;      height: 600px;      background-color: green;    }    #bigest{      position: static;      left: 20px;      margin-top: 20px;      width: 500px;      height: 500px;      background-color: #ab2;    }    #biger{      position: static;      left: 20px;      margin-top: 30px;      width: 400px;      height: 400px;      background-color: #00f;    }    #big{      position: relative;      left: 20px;      margin-top: 40px;      width: 300px;      height: 300px;      background-color: #000;    }    #normal{      position: static;      margin-left: 20px;      margin-top: 50px;      width: 200px;      height: 200px;      background-color: #aaa;    }    #middle{      position: absolute;      left: 20px;      margin-top: 60px;      width: 100px;      height: 100px;      background-color: #aaa;    }    #small{      position: fixed;      left: 20px;      margin-top: 70px;      height: 50px;      width: 50px;      background-color: #f00;    }               

small

查看更多关于DOM中关于脱离文档流的几种情况分析_html/css_WEB-ITnose的详细内容...

  阅读:41次