Reputation: 136
So I have a header with two buttons, login and join, and I have it so that when the user hovers over one of the buttons, and drops a container with a few inputs and a button. I want the dropdown to fade in with css opacity
but I can't get it to work Maybe there is some other better way. Thanks, and here's a 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;
}
Upvotes: 0
Views: 2694
Reputation: 1345
If you set the max-height to 0px with overflow hidden it will be as if it is display none and will not show.
Then when the state changes set max-height to something large (big enough to contain the area) like 400px. It will then appear as if it was hidden none to hidden block.
.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;
}
Upvotes: 0
Reputation: 136
Okay, thanks to this link that someone commented, I've come up with the following css which works great. I've decided I like it better if there is no fade in and out, but simply a delay, but I still use the css transition
for it:
#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;
}
Upvotes: 0
Reputation: 4149
The contains are set to "display: none;" to hide them. On hover, they are set to "display: block" which immediately displays them and ignores the opacity transition. Personally, I find this "bug" very irritating (it isn't a bug...but, it's annoying).
Two work arounds are Javascript (messy) and using CSS Keyframe animations. http://hschwarz77.wordpress.com/2013/10/16/css-transition-from-display-none-to-display-block-on-hover/
To the best of my knowledge, these are the only solutions to have the div completely hidden (and unusable...visibility:hidden occupies the space) and fade in.
Upvotes: 2
Reputation: 3604
display: none;
on all of those elements are screwing up your transitions. You can't put a css transition on display none because it's either true or false and there's no in between.
Upvotes: 1