Can someone explain why isn't my Background Gradient property is not working.
How to achieve the background gradient without altering the position property?
NOTE : When I remove the position property from div with class="parent" it works.
And any suggestion to better the code is also appreciated.
var drop = document.querySelector(".drop");
var button = document.querySelector(".button");
button.addEventListener("click", function(){
drop.classList.toggle("animation");
});
body, html{
margin: 0;
padding: 0;
}
body{
background: linear-gradient(to right, #f98866, #ffffff);
}
.parent{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
perspective: 1000px;
}
ul{
padding: 0;
margin: 0;
margin-top: 10px;
}
li{
list-style: none;
padding: 15px 70px;
background: #80bd9e;
color: #fff;
font-family: monospace;
text-align: center;
transition: 0.3s;
}
li:hover{
background: #89da59;
transform: skewX(-10deg);
}
a{
text-decoration: none;
color: #000;
}
.button{
padding: 20px 70px;
background: #ff420e;
color: #fff;
font-family: monospace;
font-size: 1.5em;
transition: 0.4s;
}
.button:hover{
cursor: pointer;
}
.animation{
transform: rotateX(-88deg);
opacity: 0;
}
.button:hover{
transform: rotateY(10deg);
}
.drop{
transition: 1s;
}
<!DOCTYPE html>
<html>
<head>
<title>3D dropdown</title>
</head>
<body>
<div class="parent">
<div class="button">Click Me!</div>
<div class="drop animation">
<ul>
<a href="#"><li>Option</li></a>
<a href="#"><li>Option</li></a>
<a href="#"><li>Option</li></a>
<a href="#"><li>Option</li></a>
</ul>
</div>
</div>
</body>
</html>
See Question&Answers more detail:os