一、 没有width的元素始终会将宽度扩展填满其父元素为止。添加水平边框、内外边距,会导致内容宽度减少,减少量等于边框+边距
二、 设定了宽度的盒子添加边框、边距,会导致盒子扩展得更宽,实际上盒子的width属性只是设置了盒子内容区的宽度,而非盒子要占据的水平宽度
- 为父元素应用 overflow:hidden
- 浮动父元素
- 在父元素的末尾添加非浮动元素,可以直接在标记中加,亦可以通过给父元素加clearfix类来加(需要一个clearfix的样式规则)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{ margin:0; padding:0;} div{background:#ccc;} .absolute-test{position:absolute; top:100px; left:100px;} .absolute-test h1{background:#333; color:orange;} body{margin-top: 30px !important;} </style> </head> <body> <div>this is static position</div> <div class="absolute-test"><h1>I‘m absulote</h1></div> <div>this is static position</div> </body> </html>
>>bottom=0就是页脚了 ^。^
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{ margin:0; padding:0;} div{background:#ccc;} .absolute-test{position:fixed; top:0px; left:100px;} .absolute-test h1{background:#333; color:orange;} body{margin-top: 30px !important;} </style> </head> <body> <div>this is static position</div> <div class="absolute-test"><h1>I‘m absulote</h1></div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> <div>this is static position</div> </body> </html>
>>对了,这个东西拿来做导航很不错^。^...
原文:http://www.cnblogs.com/wykCN/p/4998852.html