DIV定位实例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>DIV的定位</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<h2 class="pos_abs">这是带有绝对定位的标题</h2>
<div id="first">第一个层</div>
<div id="second">第二个层</div>
<div id="third">第三个层</div>
<h2>这是位于正常位置的标题</h2>
<h2 class="pos_left">这个标题相对于其正常位置向左移动</h2>
<h2 class="pos_right">这个标题相对于其正常位置向右移动</h2>
<div class="first">第四层</div>
<div class="second">第五层</div>
</body>
</html>


//style.css
h2.pos_abs{    /*绝对定位 需设置左和上位置*/
position:absolute;
left:100px;
top:150px;
background:#fba
}
#first{  /*通过z-index来确定显示那个层*/
position:absolute;
left:110px;
top:10px;
width:400px;
height:100px;
background:#676767;
z-index:1           
}
#second{
positon:absolute;
left:110px;
top:10px;
width;300px;
height:100px;
background:#f00;
z-index:2
}
#third{  /*默认定位*/
width:100px;    
height:150px;
background:blue;
}

h2.pos_left{   /*相对定位*/
position:relative;
left:20px;
}
h2.pos_right{  /*相对定位*/
position:relative;
right:20px;
}
.first{
position:relative;
left:50px;
top:50px;
width:100px;
height:80px;
background:#f00;
}
.second{
position:relative;
left:80px;
top:80px;
width:100px;
height:80px;
background:blue;
}

运行结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值