background-position:center center 无法居中显示

<!DOCTYPE HTML>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>aaa</title>
<style>
    div{
        border:1px red solid;
        width:300px;
        height:300px;
        background-image:url(1.jpg);
        background-repeat:no-repeat;
        background-attachment:fixed;
        background-position: center center;;;
    }
</style>

</head>
<body>
<div></div>
</body>
</html>

阅读 3.8k
1 个回答

去掉background-attachment

<!DOCTYPE HTML>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>aaa</title>
<style>
    div{
        border:1px red solid;
        width:300px;
        height:300px;
        background-image:url('https://www.w3ctech.com/resource/img/logo.png?v=a1dba.png');
        background-repeat:no-repeat;
        /*background-attachment: fixed;*/
        background-position: center;
    }
</style>
</head>
<body>
<div></div>
</body>
</html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题