前端学习(1828):前端面试题之背景图片距离

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        #box{
            width: 100px;
            height: 200px;
            background: pink;
            padding: 100px;
            border: 80px solid blue;
            background-image: url("img/1.png");
            background-repeat: no-repeat;
            background-origin: content-box;
            background-position: -50px 0;
        }

        /*答案:130px*/
    </style>
</head>
<body>
<div id="box"></div>
</body>
</html>

运行结果

猜你喜欢

转载自blog.csdn.net/weixin_43392489/article/details/107500058