如何获得背景图像覆盖整个页面

问题描述 投票:0回答:2

无法获取bg.png覆盖整个页面。它只占用一个页眉空间,但是我希望整个页面都覆盖有图像,并且联系表位于其顶部。

试图将填充和边距更改为0,这没有用。标题是否有可能是整个页面?我正在从文件夹中的图像中获取背景图像。我也很难让标题从黑色和左侧变成白色和中间。为了解决这个问题,我不得不做一个单独的类,称为“测试”,以便将其移到中间。也许我在代码中出错了?

<div class="contact-section"></div>
    <h1 class="test">Contact Us</h1>
    <div class="border"></div>
    <form class="contact-form" action="index.html" method="post">
        <input type="text" class="contact-form-text" placeholder="Your name">
        <input type="text" class="contact-form-text" placeholder="Your email">
        <input type="text" class="contact-form-text" placeholder="Your Phone #">
        <textarea class="contact-form-text" placeholder="Your message">   
        </textarea>
        <input type="submit" class="contact-form-btn" value="Send">

    </form>
    margin:0;
    padding:0;
    font-family: "montserrat", sans-serif;
}

.contact-section{
    background: url(bg.png) no-repeat center;
    background-size: cover;
    padding:40px 0;
  }

  .test{
    text-align: center;
    color: #ddd;
  }

  .border{
    width:100px;
    height: 10px;
    background: #34495e;
    margin: 40px auto;
  }

  .contact-form{
    max-width: 600px;
    margin: auto;
    padding:0 10 px;
    overflow: hidden;
  }
  .contact-form-text{
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 16px 0;
    border: 0;
    background: #111;
    padding:20px 40px;
    outline: none;
    color: #ddd;
    transition: 0.5s;
  }

  .contact-form-text:hover{
    box-shadow: 0 0 10px 4px #34495e;
  }

  textarea.contact-form-text{
    resize: none;
    height: 120px; 

  }

  .contact-form-btn{
    float:right;
    border: 0;
    background: #34495e;
    color:#fff;
    padding:12px 50px;
    border-radius: 20px;
    cursor: pointer;
    transition: 0.5s;
  }
  .contact-form-btn:hover{
    background: #2980b9;
  }
html css
2个回答
0
投票

background: url(bg.png) no-repeat center;添加到您的身体。

类似这样的东西:

body {
    display: block;
    margin: 8px;
    background: url(bg.png) no-repeat center;
}

目前,您正在将背景图像添加到您的div中,但它不会覆盖整个页面。


0
投票

您可以使用此代码

        body {
            margin: 0;
            padding: 0;
            font-family: "montserrat", sans-serif;
        }   
        .contact-section{
            background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/652/codepen.png);
            background-repeat: no-repeat;
            background-position: center;
            background-size: cover;
            padding: 40px 0;
            height: 100vh;
            min-height: 100%;
        }
        .test{
            text-align: center;
            color: #ddd;
        }
        .border{
            width: 100px;
            height: 10px;
            background: #34495e;
            margin: 40px auto;
        }
        .contact-form{
            max-width: 600px;
            margin: auto;
            padding: 0 10px;
            overflow: hidden;
        }
        .contact-form-text{
            display: block;
            width: 100%;
            box-sizing: border-box;
            margin: 16px 0;
            border: 0;
            background: #111;
            padding: 20px 40px;
            outline: none;
            color: #ddd;
            transition: 0.5s;
        }
        .contact-form-text:hover{
            box-shadow: 0 0 10px 4px #34495e;
        }
        textarea.contact-form-text{
            resize: none;
            height: 120px; 
        }
        .contact-form-btn{
            float:right;
            border: 0;
            background: #34495e;
            color:#fff;
            padding:12px 50px;
            border-radius: 20px;
            cursor: pointer;
            transition: 0.5s;
        }
        .contact-form-btn:hover{
            background: #2980b9;
        }
    <div class="contact-section">
        <h1 class="test">Contact Us</h1>
        <div class="border"></div>
        <form class="contact-form" action="index.html" method="post">
            <input type="text" class="contact-form-text" placeholder="Your name">
            <input type="text" class="contact-form-text" placeholder="Your email">
            <input type="text" class="contact-form-text" placeholder="Your Phone #">
            <textarea class="contact-form-text" placeholder="Your message">   
            </textarea>
            <input type="submit" class="contact-form-btn" value="Send">
        </form>
    </div>
© www.soinside.com 2019 - 2024. All rights reserved.