目录

background-position

描述 (Description)

设置元素背景图像的初始位置(如果已指定); 值通常配对以提供x,y位置; 默认位置为0%0%。

可能的值 (Possible Values)

  • percent
  • none
  • length
  • top
  • center
  • bottom
  • left
  • right

适用于 (Applies to)

块级和替换元素

DOM语法 (DOM Syntax)

object.style.backgroundPosition = "10 30";

例子 (Example)

以下是演示如何将背景图像位置设置为距离左侧100像素的示例。

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

以下是演示如何将背景图像位置设置为距离左侧100像素和距离顶部200像素的示例。

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

它会产生以下结果 -

新页面打开
↑回到顶部↑
WIKI教程 @2018