simple selectors
combinator selectors
pseudo-class selectors
pseudo-elements selectors
attribute selectors
pseudo-class는 selector의 상태를 표현하기 위하여 사용된다.
상태에는 hover,visited,focus.. 등이 있다.
selector:pseudo-class {
property: value;
}
출저:https://www.w3schools.com/css/css_pseudo_classes.asp
https://www.w3schools.com/css/css_pseudo_classes.asp
/* unvisited link */
a:link {
color: #FF0000;
}
/* visited link */
a:visited {
color: #00FF00;
}
/* mouse over link */
a:hover {
color: #FF00FF;
}
/* selected link */
a:active {
color: #0000FF;
}
각각
link: 방문 전
visited: 방문 후
hover: 마우스 over
active: link를 클릭하고, 새탭에 키기까지(말로 설명하기 애매함)
Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective! a:active MUST come after a:hover in the CSS definition in order to be effective! Pseudo-class names are not case-sensitive.
출저: https://www.w3schools.com/css/css_pseudo_classes.asp
순서에 관한 내용도 존재한다.
p {
display: none;
background-color: yellow;
padding: 20px;
}
div:hover p {
display: block;
}
div가 hover이고 descendant element인 p에 대하여 display가 바뀌므로 tooltip기능을 css로도 구현할 수 있다.
first-child인 상태를 나타낸다. 상태라는 말이 이해도를 높이는데,
p:first-child {
color: blue;
}
아래의 예시는 자칫 이름으로 인하여 p element안에 첫번 째 요소를 선택하는 것으로 햇갈릴 수 있다(제가 그랬읍니다.) 상태라는 말을 기억한다면 p element인데 본인이 첫번 째 요소를 선택한다고 생각하면 됩니다.!
first-child가 아니라 처음으로 등장하는 상태를 의미합니다.
p:first-of-type {
color: blue;
}
<div>
<span>예시<span>
<p>파란색<p/>
<p>default<p/>
</div>
first child와 비교하였을 때, 더 잘 이해할 수 있습니다.
언어에 대한 attribute를 주었을 때 언어또한 상태로 보고 해당 언어를 selector로 지정하여 style줄 수 있습니다.
q:lang(no) {
quotes: "~" "~";
}
<p>Some text <q lang="no">A quote in a paragraph</q> Some text.</p>