2401_83940696 2024-07-21 17:40 采纳率: 2.1%
浏览 0
已结题

为什么动态背景样式被覆盖了?

以下是我的代码,我写了一个动态的背景,但引入bootstrap后就被覆盖了,
前端代码

<style>
    .navbar {
        border-radius:0
     }
    *{
        /*初始化*/
        margin:0;
        padding:0;
    }
    .account {
        width:500px;
        border:2px solid #dddddd;
        background-color: white;
        border-radius:10px;
        box-shadow:8px 10px 9px #aaa;
        margin-left:auto;
        margin-right:auto;
        margin-top:130px;
        padding:20px 40px;}
    .account h2{
        margin-top:10px;
        text-align:center;}

    body{
        /100%窗口高度/
        height:100vh;
        /*弹性布局 居中*/
        display:flex;
        justify-content:center;
        align-items:center;
        /*渐变背景*/
        background:linear-gradient(200deg,#e3c5eb,#a9c1ed);
        /*溢出隐藏*/
        overflow:hidden;}
ul li{
    position:absolute;
    border:1px solid #fff;
    background-color:#fff;
    width:30px;
    height:30px;
    list-style:none;
    opacity:0;
}
.square li{
    top:40vh;
    left:60vw;
    /* 执行动画 动画名 时长 线性的 无限次播放*/
    animation:square 10s linear infinite;
}
.square li:nth-child(2){
    top:80vh;
    left:10vw;
    /* 设置动画延迟时间*/
    animation-delay:2s
}
.square li:nth-child(3){
    top:80vh;
    left:85vw;
    /* 设置动画延迟时间*/
    animation-delay:4s
}
.square li:nth-child(4){
    top:10vh;
    left:70vw;
    /* 设置动画延迟时间*/
    animation-delay:6s
}
.square li:nth-child(5){
    top:10vh;
    left:10vw;
    /* 设置动画延迟时间*/
    animation-delay:8s
     @keyframes circle{
            0%{
                transform:scale(0) rotateY(0deg);
                opacity:1;
                bottom:0;
                border-radius:0;
            }
            100%{
                transform:scale(5) rotateY(1000deg);
                opacity:0;
                bottom:90vh;
                border-radius:50%;
            }
        }
    </style>
</head>
<body>
<div class="account">
    <h2>用户登录</h2>
    <form method="post" novalidate>
        {%csrf_token%}
        <div class="form-group">
         <i class="fa fa-user-o" aria-hidden="true"></i>
        用户名或手机号
            {{form.username}}
            <span style="color:red">{{form.username.errors.0}}</span>
        </div>
        <div class="form-group">
        <i class="fa fa-key" aria-hidden="true"></i> 密码
            {{form.password}}
            <span style="color:red">{{form.password.errors.0}}</span>
        </div>
        <div class="form-group">
            <label> <i class="fa fa-file-photo-o" aria-hidden="true"></i> 图片验证码</label>
            <div class="row">
                <div class="col-xs-7">
            {{form.code}}
            <span style="color:red">{{form.code.errors.0}}</span>
                </div>
                <div class="col-xs-5">
                    < img id="image_code" src="/image/code/" style="width:125px">
                </div>
            </div>
        </div>
        <input type="submit" value="登录" class="btn btn-info">
    </form>

</div>
<div class="square">
    <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</div>
<div class="circle">
    <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</div>
</body>
ul li{
    position:absolute;
    border:1px solid #fff;
    background-color:#fff;
    width:30px;
    height:30px;
    list-style:none;
    opacity:0;
}
.square li{
    top:40vh;
    left:60vw;
    /* 执行动画 动画名 时长 线性的 无限次播放*/
    animation:square 10s linear infinite;
}
.square li:nth-child(2){
    top:80vh;
    left:10vw;
    /* 设置动画延迟时间*/
    animation-delay:2s
}
.square li:nth-child(3){
    top:80vh;
    left:85vw;
    /* 设置动画延迟时间*/
    animation-delay:4s
}
.square li:nth-child(4){
    top:10vh;
    left:70vw;
    /* 设置动画延迟时间*/
    animation-delay:6s
}
.square li:nth-child(5){
    top:10vh;
    left:10vw;
    /* 设置动画延迟时间*/
    animation-delay:8s
}
.square li:nth-child(6){
    top:40vh;
    left:10vw;
    /* 设置动画延迟时间*/
    animation-delay:10s
}
.circle li{
    bottom:0;
    left:15vw;
    animation:circle 10s linear infinite;
}
.circle li:nth-child(2){
    left:35vw;
    animation-delay:2s
}
.circle li:nth-child(3){
    left:55vw;
    animation-delay:6s
}
.circle li:nth-child(4){
    left:75vw;
    animation-delay:4s
}
.circle li:nth-child(5){
    left:95vw;
    animation-delay:8s
}
.circle li:nth-child(6){
    left:855vw;
    animation-delay:10s
}
@keyframes square{
    0%{
        transform:scale(0) rotateY(0deg);
        opacity:1;
    }
    100%{
        transform:scale(5) rotateY(1000deg);
        opacity:0;
    }
}



后端代码

def login(request):
    """登录"""
    if request.method == 'GET':
        form = LoginForm()
        return render(request, 'login.html', {'form': form})
    form = LoginForm(data=request.POST)

    if form.is_valid():
        # 验证成功,获取到的数据
        # 验证码的校验
        user_input_code = form.cleaned_data.pop('code')
        code = request.session.get('image_code', '')
        if code.upper() != user_input_code.upper():
            form.add_error("code", "验证码错误")  # 主动显示错误信息
            return render(request, 'login.html', {'form': form})

        # 去数据库校验用户名和密码是否正确
        admin_object = models.admin.objects.filter(**form.cleaned_data).first()
        if not admin_object:
            form.add_error("password", "用户名或密码错误")  # 主动显示错误信息
            return render(request, 'login.html', {'form': form})

        # 用户名或密码正确,网站随机生成字符串,写到用户浏览器的cookie中,在写入到session中
        request.session['info'] = {"id": admin_object.id, "username": admin_object.username}
        # 用户信息保存七天
        request.session.set_expiry(60 * 60 * 24 * 7)
        return redirect('/admin/list')
    return render(request, 'login.html', {'form': form})


页面样式

img

  • 写回答

4条回答 默认 最新

  • 阿里嘎多学长 2024-07-21 17:40
    关注

    以下内容由AIGC及阿里嘎多学长共同生成、有用望采纳:


    从你提供的代码和描述来看,动态背景样式被覆盖的问题可能由以下几个原因引起:

    1. CSS样式的顺序

      • 确保你的自定义CSS样式在Bootstrap的CSS样式之后加载。这样可以确保你的自定义样式覆盖Bootstrap的默认样式。
    2. CSS选择器的特异性

      • 你的CSS选择器可能不够具体,导致样式被Bootstrap的样式覆盖。尝试使用更具体的选择器,例如ID或类名。
    3. CSS代码的完整性

      • 检查CSS代码是否有语法错误或遗漏,特别是动画和背景样式相关的代码。
    4. HTML结构

      • 确保HTML结构正确,特别是div元素的嵌套关系,这可能会影响样式的显示。
    5. 浏览器缓存

      • 清除浏览器缓存,确保加载的是最新的CSS文件。
    6. CSS代码的重复

      • 你的CSS代码中有一些重复的部分,例如ul li.square li的样式被重复定义了两次。这可能会导致样式冲突。

    建议的解决方案

    1. 调整CSS样式的顺序

      • 确保自定义样式在Bootstrap样式之后加载。
    2. 使用更具体的选择器

      • 例如,使用ID或类名来确保样式的优先级。
    3. 优化CSS代码

      • 合并重复的CSS规则,避免样式冲突。
    4. 使用浏览器开发者工具调试

      • 使用浏览器的开发者工具查看元素的实际样式,并比较预期的样式。
    5. 清除浏览器缓存

      • 清除浏览器缓存,确保加载的是最新的CSS文件。

    代码优化示例

    以下是优化后的CSS代码示例:

    <style>
        .navbar {
            border-radius: 0;
        }
        * {
            /* 初始化 */
            margin: 0;
            padding: 0;
        }
        .account {
            width: 500px;
            border: 2px solid #dddddd;
            background-color: white;
            border-radius: 10px;
            box-shadow: 8px 10px 9px #aaa;
            margin-left: auto;
            margin-right: auto;
            margin-top: 130px;
            padding: 20px 40px;
        }
        .account h2 {
            margin-top: 10px;
            text-align: center;
        }
    
        body {
            /* 100%窗口高度 */
            height: 100vh;
            /* 弹性布局 居中 */
            display: flex;
            justify-content: center;
            align-items: center;
            /* 渐变背景 */
            background: linear-gradient(200deg, #e3c5eb, #a9c1ed);
            /* 溢出隐藏 */
            overflow: hidden;
        }
        ul li {
            position: absolute;
            border: 1px solid #fff;
            background-color: #fff;
            width: 30px;
            height: 30px;
            list-style: none;
            opacity: 0;
        }
        .square li {
            top: 40vh;
            left: 60vw;
            /* 执行动画 动画名 时长 线性的 无限次播放 */
            animation: square 10s linear infinite;
        }
        .square li:nth-child(2) {
            top: 80vh;
            left: 10vw;
            /* 设置动画延迟时间 */
            animation-delay: 2s;
        }
        .square li:nth-child(3) {
            top: 80vh;
            left: 85vw;
            /* 设置动画延迟时间 */
            animation-delay: 4s;
        }
        .square li:nth-child(4) {
            top: 10vh;
            left: 70vw;
            /* 设置动画延迟时间 */
            animation-delay: 6s;
        }
        .square li:nth-child(5) {
            top: 10vh;
            left: 10vw;
            /* 设置动画延迟时间 */
            animation-delay: 8s;
        }
        @keyframes square {
            0% {
                transform: scale(0) rotateY(0deg);
                opacity: 1;
            }
            100% {
                transform: scale(5) rotateY(1000deg);
                opacity: 0;
            }
        }
        .circle li {
            bottom: 0;
            left: 15vw;
            animation: circle 10s linear infinite;
        }
        .circle li:nth-child(2) {
            left: 35vw;
            animation-delay: 2s;
        }
        .circle li:nth-child(3) {
            left: 55vw;
            animation-delay: 6s;
        }
        .circle li:nth-child(4) {
            left: 75vw;
            animation-delay: 4s;
        }
        .circle li:nth-child(5) {
            left: 95vw;
            animation-delay: 8s;
        }
        @keyframes circle {
            0% {
                transform: scale(0) rotateY(0deg);
                opacity: 1;
                bottom: 0;
                border-radius: 0;
            }
            100% {
                transform: scale(5) rotateY(1000deg);
                opacity: 0;
                bottom: 90vh;
                border-radius: 50%;
            }
        }
    </style>
    

    检查HTML结构

    确保HTML结构正确,特别是div元素的嵌套关系。以下是优化后的HTML结构示例:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>登录页面</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
        <style>
            /* CSS样式 */
        </style>
    </head>
    <body>
        <div class="account">
            <h2>用户登录</h2>
            <form method="post" novalidate>
                {% csrf_token %}
                <div class="form-group">
                    <i class="fa fa-user-o" aria-hidden="true"></i>
                    用户名或手机号
                    {{ form.username }}
                    <span style="color: red">{{ form.username.errors.0 }}</span>
                </div>
                <div class="form-group">
                    <i class="fa fa-key" aria-hidden="true"></i> 密码
                    {{ form.password }}
                    <span style="color: red">{{ form.password.errors.0 }}</span>
                </div>
                <div class="form-group">
                    <label><i class="fa fa-file-photo-o" aria-hidden="true"></i> 图片验证码</label>
                    <div class="row">
                        <div class="col-xs-7">
                            {{ form.code }}
                            <span style="color: red">{{ form.code.errors.0 }}</span>
                        </div>
                        <div class="col-xs-5">
                            <img id="image_code" src="/image/code/" style="width: 125px">
                        </div>
                    </div>
                </div>
                <input type="submit" value="登录" class="btn btn-info">
            </form>
        </div>
        <div class="square">
            <ul>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
        <div class="circle">
            <ul>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
    </body>
    </html>
    

    通过以上步骤和示例代码,你可以逐步排查并解决动态背景样式被覆盖的问题。

    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月21日
  • 创建了问题 7月21日

悬赏问题

  • ¥15 Windows Script Host 无法找到脚本文件"C:\ProgramData\Player800\Cotrl.vbs”
  • ¥15 matlab自定义损失函数
  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图