I've read in the docs and elsewhere that & refers "back to the main" Styled Component that it's inside of. For instance, in this example it refers to MyDiv and the div's text will turn red when the div is hovered:
const MyDiv = styled.div`
&:hover { color: red; }
`
The docs also say that when the ampersand isn't present, the CSS declaration will refer to children of the components, however, I've noticed, particularly with pseudo classes like :hover, that if I omit the ampersand the behavior is still the same. For example, with the code below I would think that the hover only applies to the child Text span, but if you hover just the div the text in the span still turns red.
const MyDiv = styled.div`
:hover { color: red; }
// these other style declarations are provided just to help
// illustrate what happens if you want to try this in a code editor:
color: blue;
border: 1px solid black;
width: 100%;
padding: 10px;
`
const Text = styled.span`
border: 1px solid blue;
`
export default App() {
render(
<MyDiv>
<Text>Hello world</Text>
</MyDiv>
)
}
If anybody can help shed some light on this I'd appreciate it!