I'm trying to get an animation to play when I hover over a button, but I want it to target the label div and the label p elements instead of the element that triggers it.
Also, I need it to work when only the div is hovered over, and vice versa. It should play the animation for both elements regardless if only one is being hovered over.
I could use a div I guess, to group them together, but that would be tedious and'll probably clutter the code. I already have like an entire page full of nested divs. I feel like it would be easier if I just used selectors correctly.
HTML
<html>
<head>
<link rel="stylesheet"
href="style.css">
</head>
<body>
<div class="button"
style="max-width: 157.39px; max-height: 157.39px;"
<div class="label">
<p class"label">the big</p>
</div>
</div>
</body>
</html>
CSS
@keyframes show-label {
from {
opacity: 0%;
}
to {
opacity: 100%;
}
}
body {
display: flex;
flex-direction: column;
flex: auto;
align-items: center;
}
div.button {
display: flex;
flex-direction: column;
justify-content: flex-end;
flex: auto;
width: 20vw;
height: 20vw;
background-color: lightgray;
border-radius: 10px;
}
.label {
opacity: 0%;
}
.label:hover {
animation: show-label 500ms forwards;
div.label {
background-color: rgba(0, 0, 0, 0.5);
border-radius: 0px 0px 10px 10px;
}
p.label {
color: white;
font-size: min(1.8vw, 18.17px);
text-align: center;
}