我試圖設計一個基於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