第三章 可视化格式模型html
1.盒子模型布局
》IE早期版本,包括IE6,width=内容宽度+内边距+边框htm
box-sizing属性能够定义要使用哪一种盒子模型:blog
》外边距叠加文档
2.定位get
详见博文CSS——布局模型 http://www.cnblogs.com/congyue-pepsi/p/5671506.htmlit
》对于定位的主要问题是要记住每种定位的意义:io
》局对定位与文档流无关,因此能够覆盖页面的其它元素,使用z-index控制叠放顺序class
》包含框相对定位,元素绝对定位 举例:容器
#branding { width: 70em; height: 10em; position: relative; } #branding .tel { position: absolute; right: 1em; bottom: 1em; text-align: right; } <div id="branding"> <p class="tel">Tel: 1234 123 1234</p> </div>
》注意,周围元素的尺寸改变不会影响绝对定位元素的位置,由于它已经脱离了文档流,因此容易产生覆盖重叠问题,需留意。
》浮动:
》由于浮动元素不占据空间,因此容器元素不包围它们,添加一个进行清理的空元素能够迫使容器元素包围浮动元素。
未清理:灰色包含块没有高度在最顶层
.news { background-color: gray; border: solid 1px black; } .news img { float: left; } .news p { float: right; } <div class="news"> <img src="/img/img.jpg" alt="my pic"/> <p>Some text</p> </div>
清理后:灰色包含块在全部内部元素底层包含
.news { background-color: gray; border: solid 1px black; } .news img { float: left; } .news p { float: right; } .clear { clear: both; } <div class="news"> <img src="/img/img.jpg" alt="my pic" /> <p>Some text</p> <br class="clear" /> </div>
这种方法能够解决,可是添加了多余的代码。
另外,也能够将包含块设置为左浮动,能够解决这个问题,可是会影响下一个元素,能够选择合适元素进行clear。
另外一种解决办法:
>在news后添加类名clear
添加了一个点,而后设置高度为0,同时设置不显示。
由于被清理的元素在它们的顶外边距上添加了控件,因此生成的内容须要将它的display属性改成block。这样设置以后,就能够对生成的内容进行清理。
.clear:after { content: "."; height: 0; visibility: hidden; display: block; clear: both; }