I have two divs, when one hovers over the text (which are links) of a div, the padding increases from 0 to 5px. My issue is that whenever I hover over the text and the padding increases, the divs move down. Here's the code:
<div id="container" class="text1">
<a id="text1style" href="#" style="font-family:arial;font-size:120%;
text-decoration:none;">Some text</a>
</div>
<div id="container" class="text2">
<a id="text2style" href="#" style="font-family:arial;font-size:120%;
text-decoration:none;">text</a>
</div>
#container {
position:relative;
}
a:link, a:visited, a:active {
color:blue;
}
a:hover {
color:yellow;
}
.text1box {
left:200px;
bottom:35px;
width:243px;
}
#text1style {
-webkit-transition:color 0.5s;
-o-transition:color 0.5s;
-moz-transition:color 0.5s;
-ms-transition:color 0.5s;
transition:color 0.5s;
-webkit-transition:background-color 0.5s;
-o-transition:background-color 0.5s;
-moz-transition:background-color 0.5s;
-ms-transition:background-color 0.5s;
transition:background-color 0.5s;
}
#text1style:hover {
padding:5px;
border-radius:10px;
background-color:red;
}
.text2 {
left:455px;
bottom:57px;
width:90px;
}
#text2style {
-webkit-transition:color 0.5s;
-o-transition:color 0.5s;
-moz-transition:color 0.5s;
-ms-transition:color 0.5s;
transition:color 0.5s;
-webkit-transition:background-color 0.5s;
-o-transition:background-color 0.5s;
-moz-transition:background-color 0.5s;
-ms-transition:background-color 0.5s;
transition:background-color 0.5s;
}
#text2style:hover {
padding:5px;
border-radius:10px;
background-color:red;
}
Updated code: I have applied the padding expansion to the individual links, instead of the div, and this has helped out. I still have two issues: 1) The texts (of links) still shift slightly to the right. 2) When I remove the mouse (i.e: hover ends) you can see that the text has lost padding and border radius as the background (red) fades away.
How could I resolve these two issues? Many thanks.
You can do that by moving the 2 boxes upward to compensate for the padding moving them downward.
And id should be unique
.container {
position: relative;
-webkit-transition: color 0.5s;
-o-transition: color 0.5s;
-moz-transition: color 0.5s;
-ms-transition: color 0.5s;
transition: color 0.5s;
-webkit-transition: background-color 0.5s;
-o-transition: background-color 0.5s;
-moz-transition: background-color 0.5s;
-ms-transition: background-color 0.5s;
transition: background-color 0.5s;
background-color: red;
text-align: center;
}
.box1 {
left: 200px;
/*bottom: 35px;*/
width: 221px;
border-radius: 10px;
}
.box2 {
left: 455px;
/*bottom: 57px;*/
width: 66px;
border-radius: 10px;
}
a:link,
a:visited,
a:active {
color: blue;
}
a:hover {
color: yellow;
}
.container:hover {
top: -5px;
padding: 5px 0;
background-color: dodgerblue;
}
.container.box1:hover + .box2 {
top: -10px;
}
<div id="container1" class="container box1">
<a href="#" style="font-size:120%;
text-decoration:none;">Some text</a>
</div>
<div id="container2" class="container box2">
<a href="#" style="font-size:120%;
text-decoration:none;">text</a>
</div>
Based on question edit, updated with a 2:nd sample, where I added padding: 0 5px to the a:link rule to compensate for the hovered padding
#container1, #container2 {
position: relative;
}
a:link,
a:visited,
a:active {
color: blue;
padding: 0 5px;
}
a:hover {
color: yellow;
}
.text1box {
left: 200px;
bottom: 35px;
width: 243px;
}
#text1style {
-webkit-transition: color 0.5s;
-o-transition: color 0.5s;
-moz-transition: color 0.5s;
-ms-transition: color 0.5s;
transition: color 0.5s;
-webkit-transition: background-color 0.5s;
-o-transition: background-color 0.5s;
-moz-transition: background-color 0.5s;
-ms-transition: background-color 0.5s;
transition: background-color 0.5s;
}
#text1style:hover {
padding: 5px;
border-radius: 10px;
background-color: red;
}
.text2 {
left: 455px;
bottom: 57px;
width: 90px;
}
#text2style {
-webkit-transition: color 0.5s;
-o-transition: color 0.5s;
-moz-transition: color 0.5s;
-ms-transition: color 0.5s;
transition: color 0.5s;
-webkit-transition: background-color 0.5s;
-o-transition: background-color 0.5s;
-moz-transition: background-color 0.5s;
-ms-transition: background-color 0.5s;
transition: background-color 0.5s;
}
#text2style:hover {
padding: 5px;
border-radius: 10px;
background-color: red;
}
<div id="container1" class="text1">
<a id="text1style" href="#" style="font-family:arial;font-size:120%;
text-decoration:none;">Some text</a>
</div>
<div id="container2" class="text2">
<a id="text2style" href="#" style="font-family:arial;font-size:120%;
text-decoration:none;">text</a>
</div>
I created a jsfiddle for you:
https://jsfiddle.net/squeLsa6/
<div id="" class="box1 container">
Some text
</div>
<div id="" class="box2 container">
text
</div>
<style type="text/css">
.container {
position:relative;
-webkit-transition:color 0.5s;
-o-transition:color 0.5s;
-moz-transition:color 0.5s;
-ms-transition:color 0.5s;
transition:color 0.5s;
-webkit-transition:background-color 0.5s;
-o-transition:background-color 0.5s;
-moz-transition:background-color 0.5s;
-ms-transition:background-color 0.5s;
transition:background-color 0.5s;
padding:5px;
}
a:link, a:visited, a:active {
color:blue;
padding:5px;
}
a:hover {
color:yellow;
padding:5px;
}
.box1 {
left:200px;
bottom:35px;
width:221px;
border-radius:10px;
}
.box2 {
left:455px;
bottom:57px;
width:66px;
border-radius:10px;
}
.container:hover {
background-color:dodgerblue;
}
</style>
Basically I moved the padding from the hover state to the a's and the container. I also converted container to be a class, because id's should be unique. I'm not sure exactly how you want it to work, so you may need to play with it a little, but this should get you started.
First of all, you confused the id with classes. I changed the name ID with CLASS and it works; In the Css the classes have "." and IDs have "#", be aware of this. When i hover on the div it take a padding of 5px and it is natural that the other div lightly move due to the padding.
If you don't want to move the box you have to give padding anywhere apart of padding-bottom.
Related
This question already has answers here:
How to affect other elements when one element is hovered
(9 answers)
Closed 8 years ago.
I am trying to make it so that so that a hover effect will apply for both a listed item tag and an anchor tag that it is nested in. Ideally I want it so that all the CSS is on one tag instead of split into two. I want the hover effect of the anchor tag to animate when the listed element tag is triggered. I'm assuming the solution would be to merge the styles into one but I don't know how to do it.
HTML:
<ul class="nav">
<li>
CONTACT
</li>
<li>
ABOUT
</li>
<li>
PORTFOLIO
</li>
</ul>
CSS:
body{
background: #000;
}
ul{
list-style-type:none;
display: inline-block;
}
.nav{
float:right;
list-style-type:none;
overflow: hidden;
}
.nav li{
float:right;
overflow: hidden;
color: #00bff3;
border: 1px solid #00bff3;
padding: 8px;
margin-left: 10px;
text-align: center;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
}
.nav li:hover{
background:#00bff3;
color:#000000;
}
.blue{
color: #00bff3;
text-decoration: none;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
}
.blue:hover{
color:#000000;
}
http://jsfiddle.net/2gbu5yrz/
It's easy enough to move the relevant styles to the links themselves (really where they should be anyhow):
http://codepen.io/pageaffairs/pen/PwNeEO
.blue{
color: #00bff3;
text-decoration: none;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
display: block;
text-align: center;
padding: 8px;
}
.blue:hover{
color:#000000;
background:#00bff3;
}
Maybe this is what you are looking for: Replace .blue:hover with .nav li:hover .blue.
http://jsfiddle.net/p0ahhp5c/
The solution is to make your a use block display style:
.blue{
display: block;
color: #00bff3;
text-decoration: none;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
}
Try this
.nav:hover .blue:hover {
/*your code here*/
}
i'm trying to figure out how to work some transitions? i've got an overlay div that pops up when a link is clicked but i'm trying to make it so it either fades into the div ontop or it just melts into it?
<html>
<head>
<style type="text/css">
a:link, a:visited, a:active {
text-decoration: none;
}
html, body {
max-width: 100%;
max-height: 100%;
margin-right: auto;
margin-left: auto;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
}
.button {
margin-right: auto;
margin-left: auto;
width: 100%;
height: 100%;
float: left;
padding: 10px;
background-color: transparent;
font-weight:bold;
text-decoration:none;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
}
.blockpurp {
background: purple;
}
.blockyell {
background: yellow;
}
#cover {
position:fixed;
top:0;
left:0;
background:rgba(0,0,0,0.6);
z-index:5;
width:100%;
height:100%;
display:none;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease; }
#loginScreen, #loginScreen2 {
padding: 20px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
overflow: scroll;
height:100%;
width:100%;
margin:0 auto;
position:fixed;
top: 0px;
left: 0px;
z-index:10;
display:none;
background: rgba(0,0,0,1);
border:0;
color: #fff;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
}
#loginscreen2 {
background: rgba(23,44,1,0.9);
}
#loginScreen:target, #loginScreen:target + #cover, #loginScreen2:target, #loginScreen2:target + #cover{
display:block;
opacity:9;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease; }
.cancel {
display:block;
position:fixed;
top:0px;
right:0px;
background: transparent;
color:black;
text-shadow: 0px 0px 1px rgba(255,255,255,0.9);
height:30px;
width:35px;
font-size:30px;
text-decoration:none;
text-align:center;
font-weight:bold;
}
</style>
</head>
<body>
<div align="center">
<table align="center" width="900px" height="300px">
<td width="60%" class="blockpurp">click</td>
<td width="40%" class="blockyell">click</td>
</table>
</div>
<div id="loginScreen">
LOL LOL LOL
×
</div>
<div id="cover" >
</div>
<div id="loginScreen2">
stuff stuff
×
</div>
<div id="cover" >
</div>
</body>
</html>
i tried using this code string:
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-ms-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
but that doesn't seem to work? any ideas?
The biggest problem is that you are going from display:none to display:block. There is no real way to transition between the two using css.
Instead, you could keep them all displayed and in a fixed position, but change the appearance using z-index.
Below is an example of how you could do this.
HTML:
<div id="center">
<table>
<td class="blockpurp">click</td>
<td class="blockyell">click</td>
</table>
</div>
<div id="loginScreen">
<div>
LOL LOL LOL
×
</div>
</div>
<div id="loginScreen2">
<div>
stuff stuff
×
</div>
</div>
CSS (in need of some serious organization!):
body {
position: relative;
}
#center {
position: fixed;
background: white;
width: 100%;
height: 100%;
z-index: 5;
}
table {
width: 100%;
height: 100%;
}
td {
position: relative;
min-height: 100%;
}
td a {
position: absolute;
width: 100%;
height: 100%;
top:0;
}
.blockpurp {
background: purple;
width: 60%;
}
.blockyell {
background: yellow;
width: 40%;
}
#loginScreen, #loginScreen2 {
opacity: 0;
position: fixed;
width: 100%;
height: 100%;
background:rgba(0,0,0,0.6);
top: 0;
z-index:1;
color: white;
}
#loginScreen div, #loginScreen2 div {
padding: 20px;
background: rgba(0,0,0,1);
}
.cancel {
position:fixed;
top:0px;
right:0px;
background: transparent;
color:black;
text-shadow: 0px 0px 1px rgba(255,255,255,0.9);
height:30px;
width:35px;
font-size:30px;
text-decoration:none;
text-align:center;
font-weight:bold;
}
#loginScreen:target, #loginScreen2:target {
opacity: 1;
-webkit-transition: opacity 3s;
-moz-transition: opacity 3s;
-ms-transition: opacity 3s;
-o-transition: opacity 3s;
transition: opacity 3s;
z-index:10;
}
I made the following changes in your html as well:
I took out the divs with the id 'cover'. Unlike classes, you should never have more than one element with a particular id per page. Id's should be completely unique.
I removed the inline styling. Style everything within your stylesheet!
Fiddle for reference
You need to use jquery in order to control mouse click event.
Here is a sample
$(".sample").click(function(){
$(".popup").css({
'visibility': 'visible',
'opacity': 1
});
});
As of yet, there is no way to do an HTML5 transition based on a link click. For now, you can toggle a class and attach the CSS transitions to the element being affected (which is faster + more lightweight anyway). If you attach the transition to the toggled class, then it will only do the transition when the toggled class is removed, not when it's added.
Here's an example that doesn't use jQuery—no reason to include an entire library, if you're not using it elsewhere.
HTML
<a id="clickme" href="#">click me</a>
<div id="test" class="clicked fun here">testing</div>
JavaScript
document.getElementById("clickme").onclick = function (event) {
var target = document.getElementById("test"),
classes = test.className.split(" "),
toggledClass = "clicked";
if (!!~classes.indexOf(toggledClass)) {
// same as if (classes.indexOf(toggledClass) > -1)
test.className = classes.join(" ").replace(toggledClass, "");
} else {
test.className = classes.join(" ") + " " + toggledClass;
}
}
CSS
div {
width: 100px;
height: 3em;
background-color: black;
color: white;
text-align: center;
-webkit-transition: all 250ms ease-in-out;
-moz-transition: all 250ms ease-in-out;
-ms-transition: all 250ms ease-in-out;
-o-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
}
.clicked {
color: red;
background-color: cyan;
}
fiddle
Here's my Fiddle:
#facebookIcon{
vertical-align:middle;
color:white;
font-size:5.5em;
opacity:0.4;
}
#facebookinner:hover #facebookIcon{
opacity:1.0;
}
#facebookinner{
background:#3b5998;
border-radius:100px;
height:100px;
width:100px;
margin:0 auto;
text-align:center;
line-height:100px;
opacity:0.4;
-webkit-transition:
}
#facebookinner:hover{
opacity:1.0;
}
#facebookouter {
background-color:Green;
border:5px solid rgba(0,0,0,0);
height:100px;
width:100px;
border-radius:100px;
display: table-cell;
vertical-align: middle;
-webkit-transition: height 0.2s linear, width 0.2s linear,border 0.2s ease-out,border- radius 0.2s linear,margin 0.2s linear;
transition: height 0.2s linear, width 0.2s linear,border 0.2s ease-out,border-radius 0.2s linear,margin 0.2s linear;
-moz-transition: height 0.2s linear, width 0.2s linear,border 0.2s ease-out,border-radius 0.2s linear,margin 0.2s linear;
}
#facebookouter:hover {
height:130px;
width:130px;
border-radius:130px;
border:5px solid #3b5998;
opacity:1.0;
-webkit-transition: height 0.2s linear, width 0.2s linear,border 0.2s ease- out,border-radius 0.2s linear,margin 0.2s linear;
transition: height 0.2s linear, width 0.2s linear,border 0.2s ease-out,border-radius 0.2s linear,margin 0.2s linear;
-moz-transition: height 0.2s linear, width 0.2s linear,border 0.2s ease-out,border-radius 0.2s linear,margin 0.2s linear;
}
footer {
margin-top:250px;
height:150px;
position: absolute;
right: 0;
bottom: 10;
left: 0;
padding: 5 rem;
background-color: Green;
text-align: center;
padding-top:30px;
padding-left:40px;
}
/*________________Here is the Second Icon________________*/
#twitterIcon{
vertical-align:middle;
color:white;
font-size:3.5em;
-webkit-transition:font-size 0.2s;
-moz-transition:font-size 0.2s;
transition:font-size 0.2s;
}
#twitterinner:hover #twitterIcon{
opacity:1.0;
font-size: 3.5 em
}
#twitterinner {
background:#23dcd5;
border-radius:100px;
height:100px;
width:100px;
margin:0 auto;
text-align:center;
line-height:100px;
-webkit-transition:height 0.2s, width 0.2s, line-height 0.2s;
-moz-transition:height 0.2s, width 0.2s, line-height 0.2s;
transition:height 0.2s, width 0.2s, line-height 0.2s;
}
#twitterinner:hover{
opacity:1.0;
height: 80px;
width:80px;
line-height:80px;
}
#twitterouter{
background-color:Green;
border:5px solid #23dcd5;
height:100px;
width:100px;
border-radius:100px;
display: table-cell;
vertical-align: middle;
opacity:0.7;
}
#twitterouter:hover {
opacity:1.0;
}
I`m a beginner in CSS (1 week of learning) and I saw this hover effect (at the bottom of this page for the Social Icons).
So I tried to make the same hover effect with my limited skills. After a long time I made the same effect with two divs and an Icon.
The Problem is now that:
Im not able to set a margin to any of the "Icons", this means i want a gap between the FacebookIcon and the TwitterIcon so they wont interfere like the FacebookIcon is interfering with the Twitter Icon.
How can I hover over the inner div and activating the hover of the outer div (I can not make the inner div the parent of the outer because the outer has to be bigger than the inner).
I want the FacebookIcon Outer to grow from the center and not like its doing now. (Like in the example in the Webpage mentioned above.
I've searched for this solutions long time and found nothing suitable. Probably there is a much easier way of creating this Icons, this would be another solution :)
Thanks for your advice and sorry for my bad English (German here).
Im not able to set a margin to any of the "Icons"
That's because margin property is not applicable to display: table-cell elements.
How can I hover over the inner div and activating the hover of the
outer div
Well, you need to change your strategy. Set all the necessary CSS declarations on the child (<i> tag) and change the styles on parent:hover i selector.
Here we go:
HTML:
<footer>
<a href="#" class="icon-wrapper">
<i class="icon icon-facebook"></i>
</a>
<a href="#" class="icon-wrapper">
<i class="icon icon-twitter"></i>
</a>
</footer>
CSS:
.icon-wrapper {
float: left;
display: block;
margin: 0 1.875rem;
color: white;
font-size: 5.5rem;
}
.icon-wrapper i.icon {
display: block;
width: 8rem;
height: 8rem;
line-height: 8rem;
border-radius: 50%;
opacity: 0.5;
transition: all .2s;
}
.icon-wrapper:hover i.icon {
opacity: 1;
box-shadow: 0 0 0 1.5625rem green, /* <-- = the parent's background-color */
0 0 0 1.875rem #9b59b6;
}
.icon-facebook {
background-color: #3b5998;
}
.icon-twitter {
background-color: #23dcd5;
}
WORKING DEMO.
I currently have this JSfiddle.
HTML:
<div class="refTable">
<div class="refRow">
<div class="refCell"><img src="images/test.jpg" /><p>Test 1</p></div>
<div class="refSep"></div>
<div class="refCell"><img src="images/test.jpg" /><p>Test 2</p></div>
<div class="refSep"></div>
<div class="refCell"><img src="images/test.jpg" /><p>Test 3</p></div>
</div>
</div>
CSS:
.refTable {
display:table;
max-width:919px;
width:100%;
margin:0px auto;
}
.refRow {
display:table-row;
}
.refCell {
display:table-cell;
width:291px;
text-align: center;
font-size:16px;
border:1px #ffffff solid;
padding:0px 0px 10px 0px;
background:#eaeaea;
color:#333333;
-webkit-border-radius: 20px 20px 20px 20px;
border-radius: 20px 20px 20px 20px;
resize: none;
outline:0;
transition-duration: 0.2s;
}
.refCell img {
-webkit-border-radius: 20px 20px 0px 0px;
border-radius: 20px 20px 0px 0px;
padding-bottom:5px;
}
.refCell p {
line-height: 20px;
}
.refCell:hover {
border-color:#b32f01;
background:#ffffff;
-webkit-transition: color background 0.2s ease-in-out;
-moz-transition: color background 0.2s ease-in-out;
-ms-transition: color background -0.8s ease-in-out;
-o-transition: color background 0.2s ease-in-out;
transition: color background 0.2s ease-in-out;
cursor:pointer;
color:#cacaca;
}
.refCell:hover img {
opacity:0.4;
-webkit-transition: opacity 0.2s ease-in-out;
-moz-transition: opacity 0.2s ease-in-out;
-ms-transition: opacity -0.8s ease-in-out;
-o-transition: opacity 0.2s ease-in-out;
transition: opacity 0.2s ease-in-out;
}
.refSep {
display:table-cell;
width:20px;
}
In the fiddle, no images display in the boxes. However, there normally would be. On hover, the boxes change background color, font color, and, provided there is an image, image opacity. That's fine.
Now, I would like to make it so that, on hover, an image or div "slides" up from the bottom/side/top that says "Visit this website", possibly with some sort of icon.
What is the best approach? I've really been thinking about it, but I can't come up with a solution.
I did this with just css :hover and css3 transitions.
This is the css I wrote,
.info {
position: absolute;
top: 100%;
width: 100%;
background: rgba(0, 0, 0, 0.4);
text-align: center;
-webkit-transition: top 0.6s ease-in-out;
left: 0;
color: #f7f7f7;
text-decoration: none;
}
.refCell:hover .info {
top: 0;
display: block;
}
I also added this to the .refCell class,
position: relative;
overflow: hidden;
The html I added,
<span class="info">Click to view website</span>
Here is the JSFIDDLE to see how it works.
I'm trying to create simple auto-hide menu/header with css. I use transition but I think this is not a point here.
When I hover header is should slide down and show whole content, when I move mouse away it should slideup. It works for me. I want also screen content to expand when header is slidedup. This is mayor problem. The only way I know to have div expanded on whole page (screen) is to fix its top, bottom, left & right. It does not work when top value is changing.
Please look at my code example:
http://jsbin.com/ahamid/2/edit
The green part is problematic. I tried to fix it with changing top value on hover - but it does not work when mouse is outside of content & outside of header too.
Below is code:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div id="main">
<div id="head">
<span> header </span>
</div>
<div id="content">
<span>
test content
</span>
</div>
</div>
</body>
</html>
and css:
body {
position: relative;
}
#main {
position: absolute;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
background-color: white;
}
#head {
display: block;
height: 50px;
top: -44px;
right: 0px;
left: 0px;
background-color: #fcc;
margin: 0px 3px;
position: absolute;
transition: 0.5s;
-moz-transition: 0.5s;
-webkit-transition: 0.5s;
-o-transition: 0.5s;
}
#head:hover {
height: 50px;
background-color: red;
top:0px;
transition: 1s;
-moz-transition: 1s;
-webkit-transition: 1s;
-o-transition: 1s;
}
#content {
background-color: cfc;
position: absolute;
top: 50px;
bottom: 0px;
left: 0px;
right: 0px;
margin: 3px;
transition: 1s;
-moz-transition: 1s;
-webkit-transition: 1s;
-o-transition: 1s;
}
#head span {
color: black;
font-weight: bold;
transition: 0.5s;
-moz-transition: 0.5s;
-webkit-transition: 0.5s;
-o-transition: 0.5s;
}
#head:hover span {
color: yellow;
transition: 1s;
-moz-transition: 1s;
-webkit-transition: 1s;
-o-transition: 1s;
}
#content:hover {
top: 6px;
transition: 0.5s;
-moz-transition: 0.5s;
-webkit-transition: 0.5s;
-o-transition: 0.5s;
}
I think that the problem is that you set the #content as you want it to be on hover.
What you really want is that it is always that way, and only change it (downwards; increasing top) in the hover of the #head
Change the #content to:
#content {
background-color: cfc;
.....
top: 6px;
.....
}
and modify the top in the hover of the head:
#head:hover ~ #content {
top: 50px;
transition: 0.5s;
-moz-transition: 0.5s;
-webkit-transition: 0.5s;
-o-transition: 0.5s;
}
You can do that because head and content are siblings, so you can use the sibling selector.
This way it behaves correctly, the only strange thing comes from the transitions timing being different, but you can manage this :-)