Css-background-position

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

CSS-バックグラウンド位置

説明

指定されている場合、要素の背景画像の初期位置を設定します。値は通常、x、y位置を提供するためにペアにされます。デフォルトの位置は0%0%です。

可能な値

  • パーセント
  • none
  • 長さ
  • top
  • センター
  • left

に適用されます

ブロックレベルおよび置換された要素

DOM構文

object.style.backgroundPosition = "10 30";

以下は、左側から100ピクセル離れた背景画像の位置を設定する方法を示す例です。

<table style = "background-image:url(/images/pattern1.gif); background-position:100px;">
   <tr>
      <td>
         Background image positioned 100 pixels away from the left.
      </td>
   </tr>
</table>

以下は、背景画像の位置を左側から100ピクセル、上から200ピクセル下に設定する方法を示す例です。

<html>
   <head>
   </head>

   <body>
      <p style = "background-image:url(/css/images/logo.png);
         background-position:100px 200px;">
         The background image positioned 100 pixels away from the
         left and 200  pixels from the top.up
      </p>
   </body>
</html>

それは次の結果を生成します-