Skip to content

Commit 375f3bc

Browse files
authored
Merge pull request #605 from system-ui/nesting-styles
Add additional docs for child selectors
2 parents dd0b8ba + ef23943 commit 375f3bc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/docs/src/pages/sx-prop.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,32 @@ export default props => (
146146
)
147147
```
148148

149+
## Child Selectors
150+
151+
In some cases you might want to apply styles to children of the current element.
152+
You can do so with Emotion's [nested selectors](https://emotion.sh/docs/nested).
153+
154+
If you want to reference the current class of the component, you can use the [`&`](https://emotion.sh/docs/object-styles#child-selectors) symbol.
155+
156+
```jsx
157+
/** @jsx jsx */
158+
import { jsx } from 'theme-ui'
159+
160+
export default props => (
161+
<div
162+
{...props}
163+
sx={{
164+
h1: {
165+
backgroundColor: 'tomato'
166+
},
167+
'& > div': {
168+
fontSize: [2, 3, 4]
169+
}
170+
}}
171+
/>
172+
)
173+
```
174+
149175
## Raw CSS
150176

151177
To opt-out of using theme-based CSS, use the `css` prop to render raw CSS values.

0 commit comments

Comments
 (0)