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