所以我有一个带有两个按钮的标题,登录和连接,我有它,以便当用户将鼠标悬停在其中一个按钮上时,放下一个带有几个输入和一个按钮的容器。我希望下拉列表能够用css opacity
淡入淡出,但是我无法让它工作也许还有其他更好的方法。谢谢,这是fiddle。
HTML:
<div id="membership_container">
<div id="login_button">
<span id="login_text">Login</span>
<div class="form_containers" id="login_box">
<div class="form_inner_containers">
<form action="/login" method="POST">
<input class="inputs" placeholder="Email" type="text" name="login_email"/>
<input class="inputs" placeholder="Password" type="password" name="login_password"/>
<input class="buttons" type="submit" value="Login"/>
</form>
</div>
</div>
</div><!--
--><div id="join_button">
<span id="join_text">Join</span>
<div class="form_containers" id="join_box">
<div class="form_inner_containers">
<form action="/join" method="POST">
<input class="inputs" placeholder="Your Name" type="text" name="name"/>
<input class="inputs" placeholder="Email" type="text" name="email"/>
<input class="inputs" placeholder="Password" type="password" name="password"/>
<input class="buttons" type="submit" value="Join"/>
</form>
</div>
</div>
</div>
</div>
CSS:
#membership_container {
float: right;
position: relative;
vertical-align: top;
display: inline-block;
height: 100%;
margin: 0px;
padding: 0px;
background-color: #444444;
text-align: center;
}
#login_button {
position: relative;
vertical-align: top;
display: inline-block;
float: left;
height: 100%;
margin: 0px;
padding: 0px 10px;
background-color: #444444;
border-left: 2px solid #7B7B7B;
border-right: 2px solid #7B7B7B;
cursor: pointer;
cursor: hand;
}
#login_button:hover {
background-color: #696969;
}
#login_button #login_box {
display: none;
opacity: 0.0;
}
#login_button:hover #login_box {
display: block;
opacity: 1;
}
#login_text {
position: relative;
margin: 9px 0px 0px;
text-align: center;
color: white;
display: inline-block;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
}
#join_button {
position: relative;
vertical-align: top;
display: inline-block;
float: left;
height: 100%;
margin: 0px;
background-color: #444444;
padding: 0px 10px;
border-right: 2px solid #7B7B7B;
cursor: pointer;
cursor: hand;
}
#join_button:hover {
background-color: #696969;
}
#join_button:hover #join_box {
display: block;
opacity: 1.0;
}
#join_text {
position: relative;
margin: 9px 0px 0px;
text-align: center;
color: white;
display: inline-block;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
}
.button_blur {
background-color: #444444;
}
.button_blur:hover {
background-color: #696969;
}
.button_focus {
background-color: #696969;
}
.form_containers {
z-index: 10;
position: absolute;
display: none;
opacity: 0.0;
border: 5px solid #888888;
border-radius: 10px 0px 10px 10px;
background-color: #F1F1F1;
-o-transition: opacity .8s linear;
-ms-transition: opacity .8s linear;
-moz-transition: opacity .8s linear;
-webkit-transition: opacity .8s linear;
transition: opacity .8s linear;
}
#login_box {
top: 35px;
right: -2px;
/*left: -115px;*/
}
#join_box {
top: 35px;
right: -2px;
/*left: -73px;*/
}
.form_inner_containers {
position: relative;
margin: auto auto;
display: block;
background-color: #F1F1F1;
border-radius: 10px;
border: 0px;
}
.form_hidden {
display: none;
}
.form_shown {
display: block;
}
.inputs {
border-radius: 8px;
background-color: white !important;
outline: none;
border: 0px;
font-size: 22px;
padding: 10px;
margin: 10px;
box-shadow: 0px 0px 0px grey;
}
.inputs:focus {
box-shadow: 3px 3px 3px grey;
}
.buttons {
position: relative:
display: block;
background-color: #00ADEF;
margin: 10px;
border-radius: 8px;
padding: 10px 15px 8px;
width: 269px;
outline: none;
font-size: 22px;
border: 0px;
cursor: pointer;
cursor: hand;
color: #F1F1F1;
}
.buttons:hover {
background-color: #18B4EF;
}
.buttons:active {
background-color: #91D6F0;
color: #F1F1F1;
outline: none;
}
答案 0 :(得分:2)
包含设置为“display:none;”隐藏它们。在悬停时,它们被设置为“display:block”,它会立即显示它们并忽略不透明度转换。就个人而言,我发现这个“虫子”非常恼人(这不是一个bug ......但是,它很烦人)。
两个解决方法是Javascript(凌乱)和使用CSS Keyframe动画。 http://hschwarz77.wordpress.com/2013/10/16/css-transition-from-display-none-to-display-block-on-hover/
据我所知,这些是将div完全隐藏(并且无法使用......可见性:隐藏占据空间)和淡入的唯一解决方案。
答案 1 :(得分:1)
display: none;
都会搞砸你的过渡。您不能将css转换显示为none,因为它既可以是true也可以是false,并且介于两者之间。
答案 2 :(得分:0)
好的,感谢有人发表评论的this link,我想出了下面的css,效果很好。如果没有淡入淡出,我决定我更喜欢它,但只是延迟,但我仍然使用css transition
:
#membership_container {
float: right;
position: relative;
vertical-align: top;
display: inline-block;
height: 100%;
margin: 0px;
padding: 0px;
background-color: #444444;
text-align: center;
}
#login_button {
position: relative;
vertical-align: top;
display: inline-block;
float: left;
height: 100%;
margin: 0px;
padding: 0px 10px;
background-color: #444444;
border-left: 2px solid #7B7B7B;
border-right: 2px solid #7B7B7B;
cursor: pointer;
cursor: hand;
}
#login_button:hover {
background-color: #696969;
}
#login_button:hover #login_box {
visibility: visible;
opacity: 1;
transition-delay: .5s;
}
#login_text {
position: relative;
margin: 9px 0px 0px;
text-align: center;
color: white;
display: inline-block;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
}
#join_button {
position: relative;
vertical-align: top;
display: inline-block;
float: left;
height: 100%;
margin: 0px;
background-color: #444444;
padding: 0px 10px;
border-right: 2px solid #7B7B7B;
cursor: pointer;
cursor: hand;
}
#join_button:hover {
background-color: #696969;
}
#join_button:hover #join_box {
visibility: visible;
opacity: 1.0;
transition-delay: .5s;
}
#join_text {
position: relative;
margin: 9px 0px 0px;
text-align: center;
color: white;
display: inline-block;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
}
.button_blur {
background-color: #444444;
}
.button_blur:hover {
background-color: #696969;
}
.button_focus {
background-color: #696969;
}
.form_containers {
z-index: 10;
position: absolute;
opacity: 0;
visibility: hidden;
border: 5px solid #888888;
border-radius: 10px 0px 10px 10px;
background-color: #F1F1F1;
-o-transition: visibility 0s linear .5s, opacity 0s linear .5s;
-ms-transition: visibility 0s linear .5s, opacity 0s linear .5s;
-moz-transition: visibility 0s linear .5s, opacity 0s linear .5s;
-webkit-transition: visibility 0s linear .5s, opacity 0s linear .5s;
transition: visibility 0s linear .5s, opacity 0s linear .5s;
}
#login_box {
top: 35px;
right: -2px;
/*left: -115px;*/
}
#join_box {
top: 35px;
right: -2px;
/*left: -73px;*/
}
.form_inner_containers {
position: relative;
margin: auto auto;
display: block;
background-color: #F1F1F1;
border-radius: 10px;
border: 0px;
}
.form_hidden {
display: none;
}
.form_shown {
display: block;
}
答案 3 :(得分:0)
如果将max-height设置为0px且隐藏溢出,则它将显示为none,并且不会显示。
然后当状态改变时将max-height设置为大(足够大以包含区域),如400px。然后它会显示为隐藏块没有隐藏。
.form_before_state_change {
max-height:0px;
overflow:hidden;
opacity: 0;
-o-transition: opacity .8s linear;
-ms-transition: opacity .8s linear;
-moz-transition: opacity .8s linear;
-webkit-transition: opacity .8s linear;
transition: opacity .8s linear;
}
.form_after_state_change {
max-height:400px;
opacity: 1;
}