So My function is:
function onClickChange(props) {
let MyDiv = document.getElementById('myDIV')
let InterfaceDesign = document.getElementById('interfaceDesign')
if (MyDiv.style.display === 'none') {
MyDiv.style.display = ''
InterfaceDesign.classList.add('active')
} else {
MyDiv.style.display = 'none'
InterfaceDesign.classList.remove('active')
}
}
From this function in DOM I can see that it's getting the active class. But from my styled component:
const FirstDivElement = styled.div`
position: relative;
overflow: hidden;
width: 100%;
background-color: #000;
&:hover {
background-color: #e6007e;
transform: scale(1.05);
}
&:active{
background-color: #e6007e;
}
`
It is not getting the style of &:active
My div element is:
<div id="interfaceDesign">
<div onClick={onClickChange}>
<ListItems
headingText="Interface Design"
backgroundImage={props.secondBackgroundImage}
>
<Img
style={{
height: '50px',
width: '50px',
}}
sizes={props.interfacedesign}
/>
</ListItems>
</div>
</div>
<div id="myDIV" style={{ display: 'none' }}>
<InterfaceDesign
secondBackgroundImage={props.secondBackgroundImage}
interfacedesignMagenta={props.interfacedesignMagenta}
/>
</div>
</div>
Can anyone please help? Thank you in advance :D
You're providing styles for the :active pseudo-class, which is only used for when an element is being activated (e.g. during a mouse click). You probably want to change from &:active
to &.active
in your styled component CSS.
Also, you should note that you usually would alter styles based on props with Styled Components. You can do what you're doing, but it's less common.
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