Skip to content

Commit ef23943

Browse files
committed
Add additional docs for child selectors
It's not always immediately clear that you can use Emotion selectors which also access the theme, so this adds an explicit section showing some usage.
1 parent f6380fc commit ef23943

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)