CSS Tutorials

adplus-dvertising
Margin In CSS
Previous Home Next

Margin clears an area outside the border.The margin represents the distance between the outer edge of the border and any neighboring elements. This is often a source of confusion as it’s easy to think of the margin as a kind of “padding” between elements. Better to think of it like the margin of a page, it represents the outer edge of the object.

The margin property applies space outside the box, between the box and the browser window, or between the box and the other elements in the document.

margin: <margin-top>
<margin-right>
<margin-bottom>
<margin-left>
Simple Example
<HTML>
<HEAD>
<TITLE>Examples of margins</TITLE>
<STYLE type="text/css">
UL { 
background:#666666; 
width:35%;
margin: 12px 12px 12px 12px;
padding: 5px 5px 5px 5px;
}
LI {  
background:red;
margin: 12px 12px 12px 12px ;
padding: 12px 0px 12px 12px;
list-style:none; 
font:Arial, Helvetica, sans-serif; 
color:#000000;
}
LI.withborder {
border-style:solid;
border-width: medium;
border-color:#FFFF00;
}
</STYLE>
</HEAD>
<BODY>
<UL>
<LI class="withborder">Element of list is
a bit longer to illustrate wrapping.</LI>
</UL>
</BODY>
</HTML>

Output

Previous Home Next