The style
property does not have support for selectors.
To properly implement your styling logic, it is recommended to transfer it into a <style>
element or a linked stylesheet <link>
.
There are numerous React-friendly libraries available that can assist in generating styles dynamically. An example of this is Styled Components, which is well-known for supporting the SCSS syntax you are utilizing (with the exception of an extra space after the &
).
import { styled } from 'styled-components';
const MySpan = styled.span`
color: red;
cursor: pointer;
&:hover {
text-decoration: underline;
}
`;
Following that,
<MySpan>Click this.</MySpan>
However, it should be noted that span elements are not intended for interaction. They are not identified as clickable by screen readers and cannot be tabbed to without using a mouse. This presents a significant accessibility obstacle. If there is a need for users to interact by clicking on something, it is advisable to use a link (if directing somewhere) or a button (for other interactions).