This is the css that targets the child element, "#overlay", when the parent, ".collection", is hovered.
.collection {
position: relative;
overflow: hidden;
}
.collection:hover #overlay {
position: absolute;
opacity: .3;
}
This is the html:
import styles from "./Home.module.css";
<div className={`${styles.collection} card`}>
<div id="overlay"></div>
</div>
The properties are not applied to the child element when the parent is hovered.
The problem is that by default Next.js uses css module when importing css from Components, that means that import of css will return an object with class & id map to uglified strings.
You need to use class selector and use it on the child component.
.collection {
position: relative;
overflow: hidden;
}
.collection:hover .overlay {
// -----------^
position: absolute;
opacity: .3;
}
import styles from "./Home.module.css";
<div className={`${styles.collection} card`}>
<div id="overlay" className={styles.overlay}></div>
// --------------------------------^
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With