So each styled-component applies it's style to the global CSS-scope independent from the other components.
If you would rewrite it in in pure CSS it would look like this:
Each CSS class here is also independent from each other like in styled-components.
The only difference between the pure CSS approach and styled-components is where you define the name of the component.
In the CSS part you do it with the className property and in the styled-components approach you define it with the const ComponentName = styled.div() variable name.
Styled-components simply reuses a different approach to CSS where you write component-based code in CSS (which is much older than styled-compoents itself, for example see BEM) and because of this it makes sense to follow this paradigm also in styled-components.
That's exactly the point why styled-components is different from nested styles because it follows a component pattern instead of a nesting pattern.
To illustrate this, let's take a look how your code would be written completely in styled-components:
So each styled-component applies it's style to the global CSS-scope independent from the other components.
If you would rewrite it in in pure CSS it would look like this:
Each CSS class here is also independent from each other like in styled-components.
The only difference between the pure CSS approach and styled-components is where you define the name of the component.
In the CSS part you do it with the
className
property and in the styled-components approach you define it with theconst ComponentName = styled.div()
variable name.Styled-components simply reuses a different approach to CSS where you write component-based code in CSS (which is much older than styled-compoents itself, for example see BEM) and because of this it makes sense to follow this paradigm also in styled-components.
Thank you for detailed explanation. I will follow this approach as much as possible.