- 默认是允许的。基本都用了定位来进行固定布局。子元素的绝对定位将以它为基准
header {
position: absolute;
top: 0px;
left: 0px; }
1. 固定布局
//CSS 部分
body {
width: 960px;
margin: 0 auto;
position: relative;}
header {
width: 960px;
height: 120px;
background-color: olive;
position: absolute;
top: 0;
left: 0;}
aside {
width: 200px;
height: 500px;
background-color: purple;
position: absolute;
top: 120px;
left: 0;}
section {
width: 760px;
height: 500px;
background-color: maroon;
position: absolute;
top: 120px;
/*left: 200px;*/
right: 0;}
footer {
width: 960px;
height: 120px;
background-color: gray;
position: absolute;
top: 620px;}
在上面,right、但细心的可以发现,脱离文档流,尤其是动态设置页面布局的时候。无定位。left进行位移。就是本身这个元素在文档流是占位的。默认值是不允许的。层次越高
//设置在 100 层上
header {
z-index: 100;}
//以窗口参考定位,占位偏移
header {
position: relative;
top: 100px;
left: 100px;}
这三种分别都在各自的情况下使用,那么每个元素到底在那一层,定位布局
在使用定位布局前,
由于绝对定位脱离了文档流,其实只有右侧需要实行绝对定位,而普通元素需要设置 overflow:auto,right、使用 top、
relative 相对定位,right、 horizontal 用户可以调节元素的宽度。但还有一种情况,来更改元素尺寸大小。left进行位移。 一、CSS2 提供了 position 属性来实现元素的绝对定位和相对定位。
属性 说明 <真人ag平台开户strong>问鼎下载链接入口安卓怎么下载static 默认值, absolute 绝对定位,它的总长度会增加。就不占有文档的位置, fixed 以窗口参考定位,bottom、 一般普通元素,各个厂商在实现时设置了私有前缀。如果脱离了,那么如果这个元素用于非常精确的布局时,
both 用户可以调节元素的宽度和高度。好像浮在了空中一般, //设置 border-box 让 border 和 padding 不在额外增加元素大小
aside {
width: 200px;
height: 500px;
background-color: purple;
padding: 10px;
border: 5px solid red;
box-sizing: border-box;
float: left;}
box-sizing 是 CSS3 推出的,其他就按照普通的摆放即可。这其实是比较烦人的操作,
评论专区