*
로 나타냄* {
color : green;
}
h2 {
color : purple;
}
.
을 사용하여 나타냄.blue {
color : blue;
}
<ul>
<li class="blue red">Toy Story</li>
</ul>
#welcome-title {
color : red;
}
[attr]
<a href="http://example.com" target="_blank">
Example Link
</a>
a[target] {
color : hotpink;
}
✔ target
이라는 속성을 가진 애들만 선택하여 적용
[attr=value]
input
을 선택할 때 많이 씀<input type="text">
<input type="submit">
<input type="reset">
input[type="text"] {
background-color : red;
}
[attr^=value]
<a href="http://example.com" target="_blank">
Example Link
</a>
a[href^="http://"] {
font-style: italic;
}
✔ http:// 로 시작하는 애들만 선택해주세요!
[attr$=value]
<a href="http://example.com" target="_blank">
Example Link
</a>
a[href$=".com"] {
color : silver;
}
✔ .com 으로 끝나는 애들만 선택해주세요!
[attr*=value]
<a href="http://example.com" target="_blank">
Example Link
</a>
a[href*="example"] {
color : sienna;
}
✔ example 을 가지고 있는 애들만 선택해주세요!
first-child
: 첫번째 자식 요소 선택
last-child
: 마지막 자식 요소 선택
nth-child(n)
: n번째 자식 요소 선택
first-of-type
: 어떤 특정 타입들만 모아서 센 다음, 그 그룹에서의 첫번째 자식 요소 선택
last-of-type
: 어떤 특정 타입들만 모아서 센 다음, 그 그룹에서의 마지막 자식 요소 선택
nth-of-type(n)
: 어떤 특정 타입들만 모아서 센 다음, 그 그룹에서의 n번째 자식 요소 선택
<h2>Movie List</h2>
<section>
<div>Toy story</div>
<p>Zootopia</p>
<p>Inside Out</p>
<div>Coco</div>
<p>Finding Nemo</p>
</section>
p:first-child {
color: red;
}
📌 section
이라는 부모요소 안에서의 첫번째 자식 요소가 p
가 아니기 때문에 선택되지 않음
📌 p:first-of-type
을 사용해야 Zootopia가 선택되어 적용됨
<form>
<input type="text" placeholder="name">
<input type="email" placeholder="email">
<input class="pw" type="password" placeholder="password">
<input type="submit">
</form>
input:not(.pw) {
background-color : hotpink;
}
✔ input
중에서 pw 클래스 이름을 가진 요소를 제외하고 배경색을 적용해라!
input:not([type=email]) {
background-color : hotpink;
}
✔ input
중에서 타입이 email인 요소를 제외하고 배경색을 적용해라!
hover
: 마우스(포인터)가 올라가 있는 동안의 상태input[type=button]:hover {
backgroung-color: skyblue;
border: none;
cusor : pointer;
}
active
: 마우스(포인터)가 클릭하는 동안의 상태input[type=button]:active {
backgroung-color: red;
}
focus
: 특정 요소가 포커싱 되었을 때. 대화형 콘텐츠에서 사용 가능input[type=text]:focus {
backgroung-color: blue;
color : white;
}
<div>
<input type="text" placeholder="1">
<input type="text" placeholder="2">
<input type="text" placeholder="3" disabled>
</div>
<div>
<input type="radio" name="my-input" id="yes">
<label for="yes">Yes</label>
<input type="radio" name="my-input" id="no">
<label for="yes">no</label>
</div>
<div>
<input type="checkbox" name="check-me" id="check-me">
<label for="check-me">Check me!</label>
</div>
enabled
: disable을 제외하고 활성화되어있는 애들에게만 적용됨input[type=text]:enabled {
background-color: skyblue;
}
disabled
: 비활성화되어있는 애들에게만 적용됨input[type=text]:disabled {
background-color: silver;
}
checked
: 체크된 애들에게만 적용됨input[type=text]:checked {
outline: 3px solid red;
}
content
라는 요소를 추가해야함<div class="movie">Toy Story</div>
<div class="movie favorite">Zootopia</div>
<div class="movie">Inside Out</div>
<div class="movie favorite">Coco</div>
<div class="movie">Finding Nemo</div>
before
after
: 앞/뒤를 꾸며줌.favorite::before {
content: 'Best';
}
✔ favorite 이라는 클래스 네임을 가진 것들 앞에 Best가 붙음!