I have below example where I am trying to render a YouTube card. The issue I am facing is that the play button white background is not adjusting into the play icon that I am setting through my CSS styles. I am trying to undertand why that is not working.
Also, when I hover the card, I should see a background that says Video Test, but that never gets rendered.
https://stackblitz.com/edit/ndu1t6?file=src%2Fexample.tsx,src%2FYoutubeCard.tsx
Why is this part giving the trouble?
'&:hover': {
transform: 'scale(1.05)',
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.2)',
},
'&:hover $overlay': {
backgroundColor: 'rgba(0, 0, 0, 0.6)',
},
'&:hover $textOverlay': {
opacity: 1,
},
'&:hover $playButton': {
opacity: 0,
},
2
Answers
I tried many ways to handle the nested code issue and checked the documentation, but I could not find any way to style the child on parent hover inside
makeStyles
. Finally, I use a similar package calledreact-jss
to style elements.NOTE: Some property is not working because they are override by
fluent ui
so I have added!important
in many properties without it properties will not be applied.You can use
react-jss
package to achieve your output:Install
react-jss
package:I think the underlying issues are:
fluentui
css styled. By adding!important
you can force your styles to be used.overlay
,textOverlay
andplayButton
should probably not be seperated into siblingdiv
-elements, instead you can group them together.Here is my code (although the styling might not be exactly what you intended to do):