OneCompiler

Example of margin in CSS

example of margin in CSS

1 Answer

3 years ago by

Example Limk:
https://onecompiler.com/html/3ydkpna2d

Output
The red colored area is the margin of #target div

HTML Code

 <!DOCTYPE html>

<html>

  <head>
    <title>CSS margin example!</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    
    <div id="cont">
      <div id="target"></div>
    </div>
    
    <script src="script.js"></script>
  </body>
</html>

CSS Code

#cont{
   border: 2px solid black;
   background-color: red;
   
   min-width: 50px;
 }
#target{
  border: 2px solid black;
  background-color: white;
  
  height: 75px;
  
  margin: 15px;
}
3 years ago by ShiniGami2004