Home  >  Article  >  Web Front-end  >  The use of margin property in CSS

The use of margin property in CSS

WBOY
WBOYforward
2023-08-31 21:25:111072browse

CSS 中 margin 属性的使用

margin attribute defines the space around an HTML element. Negative values ​​can be used to overlap content. It specifies a shorthand property for setting margin properties in a declaration.

Example

You can try running the following code to set the margins -

<html>
   <head>
   </head>
   <body>
      <p style = "margin: 20px; border:2px solid yellow;">
         All four margins will be 20px
      </p>
      <p style = "margin: 15px 4% -10px; border:2px solid red;">
         Top margin will be 15px, left and right margin will be 4% of the total width of the document, bottom margin will be -10px
      </p>
   </body>
</html>

The above is the detailed content of The use of margin property in CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete