기존 App.js
import "./styles.css";
export default function App() {
return <button id="practice">Practice!</button>;
}
기존 CSS
* {
margin: 0.5rem;
}
#practice {
padding: 1rem;
font-size: 2rem;
background: powderblue;
border-radius: 1rem;
transition: 0.5s;
}
#practice:hover {
background: cornflowerblue;
color: white;
transition: 0.5s;
}
Styled Components로 작성 시
import styled from "styled-components"
import {createGlobalStyle} from "styled-components"
const Button = styled.button`
padding: 1rem;
font-size: 2rem;
background: powderblue;
border-radius: 1rem;
transition: 0.5s;
// 호버 시
&:hover{
background: cornflowerblue;
color: white;
transition: 0.5s;
}
}
`;
const GlobalStyle = createGlobalStyle`
button {
margin: 0.5rem;
}
`
export default function App() {
return (
<>
<GlobalStyle />
<Button>Practice!</Button>
</>
)
}
'코딩' 카테고리의 다른 글
Redux (0) | 2022.07.07 |
---|---|
[React] Custom Component (0) | 2022.06.30 |
[UI / UX] UI / UX 분석 (0) | 2022.06.29 |
[JS] 시간복잡도 (0) | 2022.06.29 |
[UI / UX] (0) | 2022.06.27 |