无法获取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;
}
答案 0 :(得分:1)
您可以使用此代码
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>
答案 1 :(得分:1)
background: url('image path') no-repeat;
background-size: cover;
使用这些样式
答案 2 :(得分:0)
将background: url(bg.png) no-repeat center;
添加到您的身体。
类似这样的东西:
body {
display: block;
margin: 8px;
background: url(bg.png) no-repeat center;
}
现在,您要向div添加背景图片,而背景图片不会覆盖整个页面。
答案 3 :(得分:0)
首先创建一个适合您的背景的div。 然后使用该div来应用背景图片
.background {
width: 100%;
height: 100vh;
background: url(your image link) center no-repeat;
background-size: cover;
}