Css-margin

提供:Dev Guides
移動先:案内検索

CSS-マージン

説明

_margin_プロパティは、要素の4辺すべてのマージンの幅を設定する略記プロパティです。

可能な値

  • length -長さの値。
  • percentage -マージンの幅は、要素の包含ブロックの幅に対して計算されます。
  • auto -自動的に計算される4つのマージンすべての値を設定します。

に適用されます

すべてのHTML要素。

DOM構文

object.style.margin = "5px"

ここに例があります-

<html>
   <head>
   </head>

   <body>
      <p style = "margin: 15px; border:1px solid black;">
         all four margins will be 15px
      </p>

      <p style = "margin:10px 2%; border:1px solid black;">
         top and bottom margin will be 10px, left and right margin will be 2%
         of the total width of the document.
      </p>

      <p style = "margin: 10px 2% -10px; border:1px solid black;">
         top margin will be 10px, left and right margin will be 2% of the
         total width of the document, bottom margin will be -10px
      </p>

      <p style = "margin: 10px 2% -10px auto; border:1px solid black;">
         top margin will be 10px, right margin will be 2% of the total
         width of the document, bottom margin will be -10px, left margin
         will be set by the browser
      </p>

   </body>
</html>

これにより、次の結果が生成されます–