开发者社区 问答 正文

空内容时body的background-position值为center无法居中。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test</title>
    <style>
        body{        
            background-image: url(http://c.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=736f2a288a13632715b8ca37a4bf8cda/34fae6cd7b899e516d038ce042a7d933c9950db0.jpg);
            background-repeat: no-repeat;
            background-position:center;
        }

    </style>
</head>
<body>
    
</body>
</html>

效果很不好,图片有一半是在顶部被隐藏的
screenshot
screenshot

展开
收起
杨冬芳 2016-06-12 14:54:26 3281 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • background-position 可以设置两个值的,分别为水平和垂直方向的对齐方式,如果你想背景水平居中而垂直方向从 0 开始,可以这么设置:background-position: center top;

    2020-03-28 21:47:19 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等