【问题标题】:Background doesn't work, it goes up and get cut in half背景不起作用,它会上升并被切成两半
【发布时间】:2021-11-27 03:21:52
【问题描述】:

我正在创建一个网站登录窗口,背景是一张图片,但图片总是被切成两半并向上。

这是我正在使用的代码:

.loginbody {
    background: url(img/LoginBackground3.jfif);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    font-family: sans-ser``if;   
}

this is what it lookslike

【问题讨论】:

    标签: html css background background-image


    【解决方案1】:

    如果不查看您的 HTML 也很难判断,但您的包含元素可能不是视口的完整高度。

    如果您想制作始终填充视口的全屏背景图像,请将您的 CSS 应用于页面的 html 元素:

    html { 
      background: url(img/LoginBackground3.jfif) no-repeat center center fixed; 
      background-size: cover;
    }
    

    或者,您可以将loginbody 元素上的视口高度设置为100vh,使其成为视口的完整高度:

    .loginbody {
        background: url(img/LoginBackground3.jfif);
        background-repeat: no-repeat;
        background-size: cover;
        background-position: center;
        font-family: sans-serif;
        height:100vh;   
    }
    

    【讨论】:

    • 这很奇怪,因为我看的每个教程都共享几乎相同的背景代码行,并且只适用于他们。改变高度有效!谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多