css

css 함수는 문자열을 반환하는 함수입니다.

사용 방법

CSS 리터럴

css를 태그 함수로 사용해 CSS 문자열을 만들 수 있습니다. CSS 속성 문자열을 인자로 전달하면 클래스 목록으로 변환됩니다.

1import { css } from '@devup-ui/react'
2
3function App() {
4  return (
5    <div
6      className={css`
7        background: red;
8        width: 100px;
9        height: 100px;
10      `}
11    />
12  )
13}
1import { css } from '@devup-ui/react'
2
3function App() {
4  return (
5    <div
6      className={css`
7        background: red;
8        width: 100px;
9        height: 100px;
10      `}
11    />
12  )
13}

위 내용은 아래와 같이 렌더링/변환됩니다.

1function App() {
2  return <div className="a b c" />
3}
1function App() {
2  return <div className="a b c" />
3}
1.a {
2  width: 100px;
3}
4.b {
5  height: 100px;
6}
7.c {
8  background: red;
9}
1.a {
2  width: 100px;
3}
4.b {
5  height: 100px;
6}
7.c {
8  background: red;
9}

CSS 객체

CSS 객체를 인자로 전달하여 css 함수를 사용할 수도 있습니다.

1import { css } from '@devup-ui/react'
2
3function App() {
4  return (
5    <div
6      className={css({
7        background: 'red',
8        width: '100px',
9        height: '100px',
10      })}
11    />
12  )
13}
1import { css } from '@devup-ui/react'
2
3function App() {
4  return (
5    <div
6      className={css({
7        background: 'red',
8        width: '100px',
9        height: '100px',
10      })}
11    />
12  )
13}

위 내용은 아래와 같이 렌더링/변환됩니다.

1function App() {
2  return <div className="a b c" />
3}
1function App() {
2  return <div className="a b c" />
3}
1.a {
2  background: red;
3}
4.b {
5  width: 100px;
6}
7.c {
8  height: 100px;
9}
1.a {
2  background: red;
3}
4.b {
5  width: 100px;
6}
7.c {
8  height: 100px;
9}