#content {margin-left:-100px;}
負margin一般應用於小劑量但稍後您將看到,它是可以作得更好的。關於負margin,要注意幾件事情:css
/* Moves the element 10px upwards */ #mydiv1 {margin-top:-10px;}
/* * All elements succeeding #mydiv1 move up by * 10px, while #mydiv1 doesn’t even move an inch. */ #mydiv1 {margin-bottom:-10px;}
<div id="mydiv1">First</div> <div id="mydiv2">Second</div>
/* A negative margin is applied opposite the float */ #mydiv1 {float:left; margin-right:-100px;}
<ul> <li class="col1">Eggs</li> <li class="col1">Ham<li> <li class="col2 top">Bread<li> <li class="col2">Butter<li> <li class="col3 top">Flour<li> <li class="col3">Cream</li> </ul>
CSShtml
ul {list-style:none;} li {line-height:1.3em;} .col2 {margin-left:100px;} .col3 {margin-left:200px;} .top {margin-top:-2.6em;} /* the clincher */
<div id="content"> <p>Main content in here</p> </div>
<div id="sidebar"> <p>I’m the Sidebar! </p> </div>
CSSweb
#content {width:100%; float:left; margin-right:-200px;} #sidebar {width:200px; float:left;}
/* Prevent text from being overlapped */ #content p {margin-right:210px;} /* It’s 200px + 10px, the 10px being an additional margin.*/