I’m currently facing a problem with some css code.
What I’m trying to achieve is when somebody hovers on the link in #trigger, the div #hidden to show.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#hidden {
display: none;
position: absolute;
top: 20px;
left: 100px;
border: 1px solid red;
}
#trigger {
border: 1px solid white;
background: red;
}
#trigger:hover #hidden {
display: block !important;
}
</style>
</head>
<body>
<div id="hidden">
This hidden div.
</div>
<span id="trigger">
<a href="#">Show</a>
</span>
</body>
</html>
I’m trying to understand why the hell this code refuses to work.
I have used similar code on many places and it worked just fine.
What’s the problem here?
The div
hiddenis not in thetriggerdiv.You can let your CSS code work as follows:
Btw, take in considuration that the absolute positioning div (
#hidden) will take the x and y of the upper element with anpoistion: relativeorabsoluteas the start point (0, 0). If there isn’t any, then it takes the body’s x and y.