css元素定位
| |
Posted in 技术 on December 1, 2006 / 引用(0)

5. two column layout|两列布局
让我们实践position:relative + position:absolute的理论,实现两列布局。


example:
<div id="div-1">
<div id="div-1a">this is the column-one</div>
<div id="div-1b">this is the column-two</div>
</div>



#div-1 {
position:relative;/*父元素相对定位*/
}
#div-1a {
position:absolute;/*子元素绝对定位*/
top:0;
right:0;
width:200px;
}
#div-1b {
position:absolute;/*子元素绝对定位*/
top:0;
left:0;
width:200px;
}


注意,在这个例子中会发现父元素的高度不会随着子元素的告诉变化,所以如果父元素的背景和边框需要定义一个足够高的高度才能显示出来。

6.float|浮动对齐
使用float定位一个元素有float:left;&float:right;两种值。这种定位只能在水平坐标定位,不能在垂直坐标定位。而且让下面的元素浮动环绕在它的左边或者右边。


example:
#div-1a {
float:left;
width:200px;
}


7.make two clumn with float|浮动实现两列布局
如果让一个元素float:left;另一个float:right;控制好他们的宽度,就能实现两列的布局效果。

example:
#div-1a {
float:left;
width:150px;
}
#div-1b {
float:left;
width:150px;
}


8.clear float|清除浮动
如果你不想让使用了float元素的下面的元素浮动环绕在它的周围,那么你就使用clear,clear有三个值,clear:left;(清除左浮动),clear:right;(清除右浮动),clear:both;(清除所有浮动)。

example:
<div id="div-1a">this is div-1a</div>
<div id="div-1b">this is div-1b</div>
<div id="div-1c">this is div-1c</div>


#div-1a {
float:left;
width:190px;
}
#div-1b {
float:left;
width:190px;
}
#div-1c {
clear:both;
}


至此,这个css的定位部分就结束了,你可以动手体会体会加深印象。
» 内文分页: [1] [2]
This entry comes from 本站原创 and has been read for 4770 times.It is tagged with .
0 Responses
发表评论

昵称

网址

电邮

OpenID登入 高级选项 表情