html - 如何使用 css 制作一个页面,背景图像被覆盖,滚动且响应迅速?

标签 html css

我想制作一个页面,通过向下滚动,内容 div 覆盖背景图像。所以我为主体放置了一个背景图像并创建了 2 个 div,它在大窗口大小下工作,但是当我改变窗口大小,并使其变小(以测试响应),图像和内容 div 之间有一个白色间隙。

你能帮我删除它吗?

       <html>
        <head>
                <meta charset="utf-8">
                <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <title>first</title>

                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
                <link href="css/first.css"  rel="stylesheet">

        <style>

        body{

            background: url("https://kalamarie123.files.wordpress.com/2012/03/img_7815-2.jpg") no-repeat top center fixed;
            background-size:100%;


        }


        </style>
        </head>


        <body>

        <div class="cover"></div>
        <div class="content">Lorem Ipsum is simply dummy text of </div>   

        </body>
        </html>



.cover{
    height: 1232px;
    width: 100%;
    margin: 0;
    padding: 0;
    color: white;
    text-align: center;

}
.content{
    width: 100%;
    height: 100%;
    background: gray;
    margin: 0;
    padding: 0;
}

最佳答案

你需要让 body 和 html 到页面底部:

body, html {
    min-height: 100%;
}

然后将背景设置为background-size: cover;: https://css-tricks.com/perfect-full-page-background-image/

关于html - 如何使用 css 制作一个页面,背景图像被覆盖,滚动且响应迅速?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35031835/

相关文章:

html - 如何将放置在 iFrame 内的 div 定位在屏幕中央

html - 水平对齐父 div 中的 UL 元素,两边都没有空格?

html - 我的 CSS 更改根本不会以任何方式影响我的网页

jquery - 静态导航栏下的 Bootstrap 轮播图片

html - iOS 邮件中的表格文本在单元格外运行

html - 文本区域背景与其在 IE 上的占位符背景图像冲突

html - 在浏览器中测试媒体查询

css - 在 CSS 中证明内联 div 的合理性

html - joomla同时有多个背景

javascript - 从一个html页面点击获取链接id并将其发送到另一个页面