freeCodeCamp/guide/chinese/css/properties/background-position-property/index.md

1.0 KiB
Raw Blame History

title localeTitle
Background Position Property 背景位置属性

背景位置属性

background-property设置背景图像应该从哪里开始的位置。换句话说此属性将采用x值和y值并将从点(x, y)开始图像。

例:

/* setting background-image of HTML doc */ 
 body { 
  background-image: url('https://i.imgur.com/6Z2VStD.png'); 
  background-repeat: no-repeat; 
  background-position: right top; 
 } 

默认情况下background-position属性设置为0% 0%

物业价值:

background-position: x-value y-value其中,

x值 left | center | right | x% | x px ,和

y值 top | center | bottom | y% | y px

其他允许的属性值是initialinherit

initial :将此属性设置为其默认值。

inherit :继承父元素的值。

**注意:**当background-property只有一个值时另一个值默认设置为center

其他资源:

MDN文档https//developer.mozilla.org/en-US/docs/Web/CSS/background-position