chrome浏览器,背景图片position设置问题

来源:2-11 background-position

慕村0193792

2018-10-24 14:32:19

老师,我的代码如下,在chrome浏览器打开后,图片显示的不是在div元素的居中位置,而是在整个屏幕的居中位置。换成数字、百分比、其他值,也是根据整个屏幕来而不是根据div元素的宽高来,请问这是什么原因?

<!DOCTYPE html>

<html>

<head>

<title>background-image</title>

<meta charset="utf-8">

<style type="text/css">

div{

width: 1200px;

height: 1500px;

background-image: url(3723.jpg_wh1200.jpg);

background-repeat: no-repeat;

background-attachment: fixed;


background-position: center;


padding: 10px;

margin:5px;

border: 2px solid;}

</style>

</head>

<body>

<div>

background-image

</div>

</body>

</html>

http://img.mukewang.com/climg/5bd011e400017eff10130613.jpg

写回答

1回答

好帮手慕夭夭

2018-10-24

你好同学 ,background-attachment: fixed;是相对于浏览器视口定位的 , 设置了此属性的背景图不会随着页面滚动而滚动 ,永远固定在视口的一个位置上 . 所以如果想相对背景图片的容器定位 ,可以使用如下属性 :

http://img.mukewang.com/climg/5bd013ea000144e309140544.jpg

希望能够帮到你 , 祝学习愉快 ,望采纳

0

0 学习 · 36712 问题

查看课程