繁体   English   中英

背景图像和 div 顶部边距的问题

[英]Issue with background image and margin top of a div

我正在尝试在 Django 表单模板上添加背景。 问题是,如果我在表格顶部没有边距,背景图像就可以了。 但是每当我尝试添加一些边距时,背景就会被分割(在我的表单顶部和页面顶部之间):

在此处输入图像描述

这是我的.html:

 <style>
        html, body {
            height: 100%;                
            background-image: url("{% static 'places/img/banana_palms.jpg' %}");
            background-size: cover;
        }
    
        .registration-form-container {
            width: 400px;
            margin: auto;
            background-color: white;
        }

        .auth-box {            
            border: 3px solid lightblue;
            border-radius: 10px;
            padding-top: 25px;
            padding-bottom: 25px;
            width:500px;
            margin:auto;
            background-color: white;
        }
        </style>
</head>

<body>
    
        <div class="auth-box text-center mt-5">
            {% block content %}
            
            {% endblock %}
        </div>
   
</body>
</html>

我应该如何更正我的代码以便背景显示得很好?

尝试将background-imagebackground-size移动到独立的body中。

改变这个

html, body {
    height: 100%;                
    background-image: url("{% static 'places/img/banana_palms.jpg' %}");
    background-size: cover;
}

对此:

html, body {
    height: 100%;                
}
body {
    background-image: url("{% static 'places/img/banana_palms.jpg' %}");
    background-size: cover;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM