HTML/CSS/CSS Attributes and Javascript Style Properties/margin

Материал из Web эксперт
Перейти к: навигация, поиск

li margin:25em 0 and padding

 


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
ul {
  list-style-type: disc;
}
li {
  padding: 0;
  margin: 0 0 0.25em 0;
}
</style>
</head>
<body>
<h3>Heading 3</h3>
<p>Text:</p>
<ul>
  <li>ONE</li>
  <li>TWO</li>
  <li>THREE</li>
  <li>FOUR</li>
  <li>FIVE</li>
</ul>
</body>
</html>



margin: 2em

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   <html>
        <head>
            <title></title>
            <style type="text/css">
        p {
            padding: 2em;
            margin: 2em;
            border: thin solid black;
            width: 10em;
            margin: auto;
        }
            </style>
        </head>
        <body>
      <p>
          p<BR/>p<BR/>p<BR/>p<BR/>p<BR/>p<BR/>
          p<BR/>p<BR/>p<BR/>p<BR/>p<BR/>p<BR/>
          p<BR/>p<BR/>p<BR/>p<BR/>p<BR/>p<BR/>
          p<BR/>p<BR/>p<BR/>p<BR/>p<BR/>p<BR/>
      </p>
        </body>
    </html>



margin: auto

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   <html>
        <head>
            <title></title>
            <style type="text/css">
        p {
            padding: 2em;
            margin: 2em;
            border: thin solid black;
            width: 10em;
            margin: auto;
        }
            </style>
        </head>
        <body>
      <p>
          This is a test. This is a test. 
      </p>
        </body>
    </html>



"margin" Example

    
<html>
<body>
<img id="myImg" 
     src="http://www.wbex.ru/style/logo.png" 
     height="100" 
     width="100" 
     border="1">
     
<button onclick="myImg.style.margin="25 25 25 25"">25 Px Margin</button>
<button onclick="myImg.style.margin="0 0 0 0"">0 Margin</button>
</body>
</html>



Margin with four values

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>margin</title>
        <style rel="stylesheet" type="text/css">
div#wrapper {
    background: yellow;
    border: 1px solid #fff;
    margin: -1px;
    width: 122px;
}
div.margin {
    width: 100px;
    height: 100px;
    background: pink;
    border: 1px solid pink;
}
div#top-right-bottom-left {
    margin-top: 10px;
    margin-right: 10px;
    margin-bottom: 10px;
    margin-left: 10px;
}
div#top-right-bottom-left-1 {
    margin: 10px 10px 10px 10px;
}        
        </style>
    </head>
    <body>
        <div id="wrapper">
            <div id="top-right-bottom-left" class="margin"></div>
            <div id="top-right-bottom-left-1" class="margin"></div>
        </div>
    </body>
</html>



Margin with three values

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>margin</title>
        <style rel="stylesheet" type="text/css">
div#wrapper {
    background: yellow;
    border: 1px solid #fff;
    margin: -1px;
    width: 112px;
}
div.margin {
    width: 100px;
    height: 100px;
    background: pink;
    border: 1px solid pink;
}
div#top-rightleft-bottom {
    margin-top: 15px;
    margin-right: 5px;
    margin-bottom: 10px;
    margin-left: 5px;
}
div#top-rightleft-bottom-1 {
    margin: 15px 5px 10px;
}        
        </style>
    </head>
    <body>
        <div id="wrapper">
            <div id="top-rightleft-bottom" class="margin"></div>
            <div id="top-rightleft-bottom-1" class="margin"></div>
        </div>
    </body>
</html>



Margin with two values

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>margin</title>
        <style rel="stylesheet" type="text/css">
body {
    margin: 0;
    padding: 0;
}
div {
    width: 100px;
    height: 100px;
    background: mistyrose;
    border: 1px solid pink;
}
div#topbottom-rightleft-1 {
    margin: 15px 5px;
}  
      
        </style>
    </head>
    <body>
        <div id="topbottom-rightleft-1"></div>
        
    </body>
</html>