使用position减少div的嵌套

以前对网页进行布局是总是使用大量的div嵌套
及时是很小的一块也嵌套div,今天看了腾讯CDC
的blog源代码,受到启发,一些小的部分的布局没有必要
嵌套div,使用position实现比较好。
以前使用的较少,现做一个例子练手,代码如下:

<!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>
<title>position-example</title>
<style type=”text/css”>
*
{
margin:0;
padding:0;
}
.title
{
width:900px;
height:100px;
margin:20px auto;
border:1px solid #ccc;
position:relative;
padding:10px;
}
.astar
{
width:43px;
height:43px;
padding:1px;
border:1px solid #ccc;
position:relative;
float:left;
}
.astar img
{
border:none;
}
.line
{
background:repeat 0 0 #D7D7D7;
width:1px;
height:41px;
margin:0 10px;
display:inline;
float:left;
margin-top:4px;
}
.title h1
{
font-size:14px;
line-height:26px;
height:26px;
}
.title p
{
font-size:12px;
line-height:15px;
height:15px;
position:relative;
}
.tag
{
margin-left:3px;
}
.commtent
{
position:absolute;
right:5px;
top:5px;
display:block;
width:60px;
height:26px;
background:red;
color:#FFF;
font-weight:bold;
padding:3px;
text-decoration:none;
}
</style>
</head>
<body>
<div>
<a href=”#”><img src=”images/1.jpg” /></a>
<i></i>
<h1>This is a title</h1>
<p>
<a href=”#” >tag1</a>
<a href=”#”>tag2</a>
2011-2-10
</p>
<a href=”#”>comtents</a>
<br />
<p>there are contents</p>
<p>there are contents</p>
</div>
<div>
<a href=”#”><img src=”images/1.jpg” /></a>
<i></i>
<h1>This is a title</h1>
<p>
<a href=”#” >tag1</a>
<a href=”#”>tag2</a>
2011-2-10
</p>
<a href=”#”>comtents</a>
</div>
<div>
<a href=”#”><img src=”images/1.jpg” /></a>
<i></i>
<h1>This is a title</h1>
<p>
<a href=”#” >tag1</a>
<a href=”#”>tag2</a>
2011-2-10
</p>
<a href=”#”>comtents</a>
</div>
</body>
</html>

点击  查看演示

本文原创,转载请注明出处:网站设计编程网

http://happysnail.org/blog/index.php/archives/448

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值