Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 함수
- flex
- align-content
- 기초
- 조건문
- for of
- 타입
- 논리연산자
- flex-wrap
- flex-direction
- typeof
- 반복문
- boolean
- 프론트엔드
- for in
- 함수표현식
- 변수
- justify-content
- 화살표함수
- 속성
- javascript
- 함수선언식
- 비교연산자
- properties
- ELSE
- if else
- frontend
- for
- Methods
- 문자열
Archives
- Today
- Total
하얀 코딩
[Styled Component - 7] & 본문
&기호는 styled-components에서 사용되는 특별한 문법 중 하나입니다.
&를 사용하여 현재 스타일링 중인 컴포넌트를 참조할 수 있습니다.
이를 통해 CSS 선택자와 유사한 방식으로 스타일을 적용할 수 있습니다.
import styled from 'styled-components';
const Button = styled.button`
padding: 10px 20px;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
/* 기본 상태 스타일 */
background-color: #fca311;
color: #ffffff;
border: none;
&:hover {
/* 호버 상태 스타일 */
background-color: #ffba08;
}
&:active {
/* 액티브 상태 스타일 */
background-color: #e85d04;
}
&:disabled {
/* 비활성 상태 스타일 */
background-color: #e0e0e0;
cursor: not-allowed;
}
`;
&는 styled-components에서 강력한 기능 중 하나이며,
다양한 CSS 선택자와 함께 사용하여 특정 상황에 맞는 스타일을 적용할 수 있습니다.
&에 대한 기호 해석은 "자기 자신" 라고 해석하면 쉽습니다!
import styled from 'styled-components';
const Card = styled.div`
background-color: #fca311;
padding: 20px;
border-radius: 4px;
&:hover {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
& h2 {
color: #ffba08;
}
}
& h2 {
color: #ffffff;
font-size: 24px;
margin-bottom: 10px;
}
`;
function Example() {
return (
<Card>
<h2>Card Title</h2>
<p>This is a sample card component.</p>
</Card>
);
}
'Styled Components' 카테고리의 다른 글
[Styled Component - 9] styled-reset (0) | 2023.08.30 |
---|---|
[Styled Component - 8] createGlobalStyle (0) | 2023.08.30 |
[Styled Component - 6] ThemeProvider (0) | 2023.06.05 |
[Styled Component - 5] keyframes (0) | 2023.06.05 |
[Styled Component - 3] attrs (0) | 2023.06.02 |