📌 기본 형태
h1 {
color: red;
font-size: 12px;
}
p {
color: black;
}
{}
내부의 여러 선언들을 작성선택자 { 하나이상의 선언 }
의 형태로 이루어진 하나의 Rule (혹은 Rule Set)📌 주석
/* 내용 */
의 형식으로 작성/* 한 줄 주석 */
/*
여러
줄을
차지하는
주석
*/
/*
span {
color: blue;
font-size: 1.5em;
}
*/
- 내부 스타일 (embedded)
내부 스타일 (embedded)
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: red;
}
</style>
<title>CSS</title>
</head>
<body>
<h1>Welcome!</h1>
</body>
</html>
인라인 스타일 (inline)
<body>
<h1 style="color:red">Welcome!</h1>
</body>
외부 스타일 (external)
<!DOCTYPE html>
<html>
<head>
<title>CSS</title>
<link rel="stylesheet" href="style/main.css" />
</head>
<body>
<h1>Welcome!</h1>
</body>
</html>
- 스타일 우선순위
스타일 우선순위
동일한 스타일이라도 선언된 곳에 따라 우선순위가 정해진다.
적용 범위가 적을 수록 우선시 된다.
소스코드의 순서가 뒤에 있으면 덮어쓴다.
스타일 상속
📌 Type Selector
h2 {
color: purple;
}
📌 ID Selector
#welcome-tilte {
color: green;
}
📌 Class Selector
.blue {
color: blue;
}
<!DOCTYPE html>
<html>
<head>
<title>CSS</title>
<link rel="stylesheet" href="style/main.css" />
</head>
<body>
<ul>
<li>
<a href="<http://example.com>" target="_blink">
Example Link (com/http)
</a>
</li>
<li>
<a href="<http://example.org>" target="_blink">
Example Link (org/http)
</a>
</li>
<li>
<a href="<https://example.com>">
Example Link (com/https)
</a>
</li>
<li>
<a href="<https://example.org>">
Example Link (org/https)
</a>
</li>
</ul>
</body>
</html>
📌 [attr]
a[target] {
color: hotpink;
}
📌 [attr=value]
a[href="<https://example.org>"] {
color: indigo;
}
📌 [attr^=value]
a[href^="https://"] {
font-style: italic;
}
📌 [attr$=value]
a[href$=".com"] {
color: silver;
}
📌 [attr*=value]
a[href*="example"] {
color: sienna;
}