• top left, left top 等价于 0% 0%.
  • top, top center, center top 等价于 50% 0%.
  • right top, top right 等价于 100% 0%.
  • left, left center, center left 等价于 0% 50%.
  • center, center center 等价于 50% 50%.
  • right, right center, center right 等价于 100% 50%.
  • bottom left, left bottom 等价于 0% 100%.
  • bottom, bottom center, center bottom 等价于 50% 100%.
  • bottom right, right bottom 等价于 100% 100%.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>background-position定位图片</title>
    <style>
        body{
            background-image: url("background-position.png");
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position:center;
        }
        .box{
            width:100px;
            height:100px;
            background-image: url("background-position.png");
            background-repeat: no-repeat;
            /*background-color: lightgoldenrodyellow;*/
            background-position:51% 35%;
        }
    </style>
</head>
<body>
<div class="box"></div>
</body>
</html>

1.png

关注友儿不迷路

Last modification:June 30th, 2021 at 10:19 pm
如果觉得我的文章对你有用,请随意赞赏