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

查看:332
本文介绍了css - 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>

解决方案

去掉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>

这篇关于css - background-position:center center 无法居中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆