Reputation: 223
Using styled-components in React, I wonder how to set pseudo selectors like :before or :after when hovering an element. This is css example:
So how to translate the css code in red rectangle with styled-components?
Upvotes: 0
Views: 3856
Reputation: 61
If the styled component is the same as the target element. You can do the following:
const Link = styled.a`
&:hover:before {
width: 100%;
}
`;
If you are targeting an element nested inside the styled component:
const LinksWrapper = styled.div`
a:hover:before {
width: 100%;
}
`;
Upvotes: 1