margin的一些技能

在一些页面底部,经常会使用到一些像关于我们之类的小导航。但是有的时候不需要用到最右边的竖线。可能有些童鞋会使用一个class来控制,但这并不是一个好技能。其实可以利用下margin负值来实现这样的效果。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="author" content="银狐">
<style>
body,ul,li,div{margin: 0;padding: 0;}
ul,li{list-style: none;}
.clearfix:after{content: "";display: block;clear: both;}
.clearfix{*zoom:1;}

.demo{ overflow: hidden; }
.demo li{ padding: 0 10px; border-left: 1px solid #AAA; margin-left: -1px; float: left; }
</style>
</head>
<body>
<ul class="demo clearfix">
        <li>关于我们</li>
        <li>关于我们</li>
        <li>关于我们</li>
        <li>关于我们</li>
</ul>
</body>
</html>

当然了,margin负值的技能肯定没有这么快就完结的,下面说下一个技能

有时候一列li并排的时候,需要一些间距的时候,又不需要最右边或者最左边有间距。这是margin负值就派上用场了。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="renderer" content="webkit">
<meta name="author" content="银狐">
<meta name="robots" content="all">
<style>
body,div,ul,li,img{margin: 0;padding: 0;}
li{list-style: none;}
.box{width: 890px;margin: 40px auto;border: 1px solid #ccc;clear: both;}
.box ul{margin-right: -10px;overflow: hidden;}
.box li{width: 290px;height: 100px;float: left;margin-right: 10px;background-color: #ccc;}
img{vertical-align: middle;}
</style>
</head>
<body>
<div class="box">
	<ul>
		<li></li>
		<li></li>
		<li></li>
	</ul>
</div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值