표기법: 콜론 하나(:)로 시작합니다.
용도 및 예시:
- :hover: 마우스가 요소 위에 올라가 있는 동안의 상태를 선택합니다.
- :active: 사용자가 요소를 클릭하고 있는 동안의 상태를 선택합니다.
- :focus: 입력 요소나 링크 등이 포커스를 받은 상태를 선택합니다.
https://velog.io/@yunn75151/HTMLCSS-Transitions 참고
p::before {
content: "→ "; /* 문단 앞에 화살표 추가 */
}
<head>
div:last-child {
background-color: teal;
}
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
<head>
div:first-child {
background-color: tomato;
}
div:last-child {
background-color: teal;
}
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
<html>
<head>
<style>
span{
background-color: tomato;
}
span:nth-child(2) {
background-color: teal;
}
</style>
</head>
<body>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
</body>
</html>
<html>
<head>
<style>
span{
background-color: tomato;
}
span:nth-child(even) {
background-color: teal;
}
</style>
</head>
<body>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
</body>
</html>
<html>
<head>
<style>
span{
background-color: tomato;
}
span:nth-child(odd) {
background-color: teal;
}
</style>
</head>
<body>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
</body>
</html>
<html>
<head>
<style>
span{
background-color: tomato;
}
span:nth-child(3n + 1) {
background-color: teal;
}
</style>
</head>
<body>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
<span>hello</span>
</body>
</html>
<html>
<head>
<style>
span{
color: tomato;
}
p span {
color: teal;
}
</style>
</head>
<body>
<span>hello</span>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
Quod commodi et sequi ipsam odio dolorem. <span>inside</span>
</p>
</body>
</html>
<html>
<head>
<style>
span{
color: tomato;
}
p > span {
color: teal;
}
</style>
</head>
<body>
<span>hello</span>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
Quod commodi et sequi ipsam odio dolorem. <span>inside</span>
</p>
</body>
</html>
<html>
<head>
<style>
span{
color: tomato;
}
p + span {
text-decoration: underline;
}
</style>
</head>
<body>
<div>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
Quod commodi et sequi ipsam odio dolorem. <span>inside</span>
</p>
<span>hello</span>
</div>
</body>
</html>
<html>
<head>
<style>
span{
color: tomato;
}
p ~ span {
text-decoration: underline;
}
</style>
</head>
<body>
<div>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
Quod commodi et sequi ipsam odio dolorem. <span>inside</span>
</p>
<span>hello</span>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
input:required {
border: 1px solid tomato;
}
</style>
</head>
<body>
<div>
<form>
<input type="text" placeholder="username" />
<input type="password" required placeholder="password" />
</form>
</div>
</body>
</html>
(출처: https://wallel.com/)
a[target] { color: red; }
a[target="_blank"] { color: red; }
<head>
<style>
input:required {
border: 1px solid tomato;
}
input[type="password"] {
background-color: thistle;
}
</style>
</head>
<body>
<div>
<form>
<input type="text" placeholder="username" />
<input type="password" required placeholder="password" />
</form>
</div>
</body>
class~="apple"] { background-color: red; }
<head>
<style>
input:required {
border: 1px solid tomato;
}
input[placeholder~="name"] {
background-color: thistle;
}
</style>
</head>
<body>
<div>
<form>
<input type="text" placeholder="user name" />
<input type="password" required placeholder="password" />
</form>
</div>
</body>
div[class|="layer"] { background-color: red; }
div[class^="minions"] { background-color: red; }
div[class$="end"] { background-color: red; }
div[class*="wow"] { background-color: red; }