我试图设计一个基于this codepen的联系表,并且浮动的表单出现在它的父div下面而不是它内部。我曾尝试添加一个没有运气的clearfix。我也对这种溢出感到厌烦,也没有运气。 CSS并不是我的强项,我在rails中这样做会让事情变得复杂,所以我很确定这只是我错过的一些愚蠢的东西。生成的HTML和我的CSS低于和here is a fiddle,在那里你可以看到它在做什么。我希望整个表单处于白色部分,而不是下面。感谢您提供任何帮助!CSS浮动的div出现在父div下面
HTML
<div id="contact">
<div id="contact-header">Contact Me</div>
<div id="form-main">
<div id="form-div">
<form accept-charset="UTF-8" action="/contacts" class="new_contact" id="new_contact" method="post">
<div style="display:none">
<input name="utf8" type="hidden" value="✓" />
<input name="authenticity_token" type="hidden" value="EoDahqxZMOLK9RYj8VfIO3lNh4EuGIcUZFv2+aWPj4Q=" />
</div>
<p class="name">
<input class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" id="contact_name" name="contact[name]" placeholder="Name" type="text" />
</p>
<p class="email">
<input class="validate[required,custom[email]] feedback-input" id="contact_email" name="contact[email]" placeholder="Email" type="text" />
</p>
<p class="text">
<textarea class="validate[required,length[6,300]] feedback-input" id="contact_message" name="contact[message]" placeholder="Message"></textarea>
</p>
<div class="submit">
<input id="button-blue" name="commit" type="submit" value="SEND" />
</div>
</form>
</div>
</div>
</div>
<!--contact-->
CSS
#contact {
background-color: white;
}
#contact-header{
text-align:center;
font-size: 40px;
color: #FAF8F2;
padding-top: 30px;
}
#form-main{
width:100%;
float:left;
padding-top:0px;
}
#form-div {
background-color:#F0B49E;
padding: 35px 35px 50px 35px;
width: 450px;
float: left;
left: 50%;
position: absolute;
margin-top:30px;
margin-left: -260px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
}
.feedback-input {
color:#3c3c3c;
font-family: "PT Sans", Helvetica, Arial, sans-serif;
font-weight:500;
font-size: 18px;
border-radius: 0;
line-height: 22px;
background-color: #FAF8F2;
padding: 13px 13px 13px 13px;
margin-bottom: 10px;
width:100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
border: 3px solid rgba(0,0,0,0);
}
.feedback-input:focus{
background: #fff;
box-shadow: 0;
border: 3px solid #A79C8E;
color: #A79C8E;
outline: none;
padding: 13px 13px 13px 54px;
}
.focused{
color:#30aed6;
border:#30aed6 solid 3px;
}
textarea {
width: 100%;
height: 150px;
line-height: 150%;
resize:vertical;
}
input:hover, textarea:hover,
input:focus, textarea:focus {
background-color:white;
}
#button-blue{
font-family: 'PT Sans', Arial, Helvetica, sans-serif;
float:left;
width: 100%;
border: #A79C8E solid 4px;
cursor:pointer;
background-color: #A79C8E;
color:white;
font-size:24px;
padding-top:22px;
padding-bottom:22px;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
margin-top:-4px;
font-weight:700;
}
#button-blue:hover{
background-color: #F0B49E;
}
.submit:hover {
color: #3498db;
}
.ease {
width: 0px;
height: 74px;
background-color: #FAF8F2;
-webkit-transition: .3s ease;
-moz-transition: .3s ease;
-o-transition: .3s ease;
-ms-transition: .3s ease;
transition: .3s ease;
}
.submit:hover .ease{
width:100%;
background-color:#A79C8E;
}
非常感谢你,我花了很多时间来解决这个问题。出于某种原因,CSS定位对我来说是世界上最困难的事情。 – kaxla
太棒了!很高兴我能帮忙。我也发现定位是一件棘手的事情。练习是解决这个问题的最好方法,所以只要有可能就试试! – Serlite