在做css这部分网页时发现一个问题,
![](https://img.haomeiwen.com/i3753845/e34d49742367c37d.png)
![](https://img.haomeiwen.com/i3753845/a54728700787bc50.png)
![](https://img.haomeiwen.com/i3753845/083ca466fed52d5a.png)
![](https://img.haomeiwen.com/i3753845/7aff6905a9518a31.png)
这个时候图片的位置并没有改变
![](https://img.haomeiwen.com/i3753845/9b9e5a392853ae87.png)
![](https://img.haomeiwen.com/i3753845/0b48f4dce7e4f0bb.png)
这个时候background-position: center; 放在background-position: top; 下面写,图片就会垂直居中
![](https://img.haomeiwen.com/i3753845/e376781c8b6b1956.png)
![](https://img.haomeiwen.com/i3753845/a295f73749959036.png)
**background-position: top; 放在background-position: center; 下面写,图片就会在顶部居中;
**
![](https://img.haomeiwen.com/i3753845/ae5a46f5867afd79.png)
![](https://img.haomeiwen.com/i3753845/697d26dfe8af648a.png)
只写个top也会水平顶部居中
![](https://img.haomeiwen.com/i3753845/4fdbc132c651fb21.png)
![](https://img.haomeiwen.com/i3753845/5b9bc419af611e24.png)
只写个center会垂直居中
同理,只写个background-position: bottom; 图片会在底部水平居中,连写的方式不论写成background:url() bottom center ;还是background:url()center bottom 图片都会在底部水平居中。
不连写时,backgroun-position: bottom, 放在background-position: center,上面的话,图片会在盒子内垂直居中。
未完成,还待修改补充。。。
网友评论