正 文

css元素定位


www.7dspace.com 更新日期:2006-5-22 8:43:49 七度空间 免费5位qq号码 免费Q币


5. two column layout|两列布局

让我们实践position:relative + position:absolute的理论,实现两列布局。

<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;两种值。这种定位只能在水平坐标定位,不能在垂直坐标定位。而且让下面的元素浮动环绕在它的左边或者右边。

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

7.make two clumn with float|浮动实现两列布局

如果让一个元素float:left;另一个float:right;控制好他们的宽度,就能实现两列的布局效果。

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

8.clear float|清除浮动

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

<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的定位部分就结束了,你可以动手体会体会加深印象。

2页,页码:[1] [2] 

上一篇:Photoshop CS2制作Web像册
下一篇:AI制版过程中常规问题及小技巧
css元素定位 作者:greengnn 来源:蓝色理想
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐