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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章