CSS : html을 꾸며주는 언어
h1 --> 선택자
{
color : yellow; --> 속성
font-size: 2em;
} --> {}:선언부
--> 규칙
/* 내용 */
<div style="..."> 내용 </div>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>inline css</title>
</head>
<body>
<p style="color: yellow;"> Hello, CSS</p>
<p style="color: yellow;"> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
<p style="color: yellow;"> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
<p style="color: yellow;"> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
</body>
</html>
(2) Internal
<style> ... <style>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>css</title>
<style>
p {color: yellow;}
</style>
</head>
<body>
<p> Hello, CSS</p>
<p> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
<p> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
<p> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
</body>
</html>
(3) External : 외부 파일을 만들어서 그 안에 넣는 방식
<link rel="stylesheet" href="css/style.css">
#style.css
p {
color : yellow;
}
#html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>External</title>
<link href="./style.css" rel="stylesheet">
</head>
<body>
<p> Hello, CSS</p>
<p> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
<p> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
<p> O Mistress mine where are you roaming? O stay and hear, your true love's coming,
That can sing both high and low. Trip no further pretty sweeting. Journeys end in lovers' meeting,
Every wise man's son doth know. </p>
</body>
</html>
h1, h2, h3, h4, h5, h6 {color : yellow; }
* {color : yellow;}
--> '*' 문서 내에 있는 전체 선택자에 스타일을 적용
h1 {color : yellow; font-size: 2em; background-color; gray;}
--> 선택자 뿐만 아니라 선언들도 그룹화가 가능하다.
h1,h2,h3,h4,h5,h6 {color: yellow; font-size:2em; background-color: gray;}
#css
.foo {font-size: 30px;}
.bar {color: blue; }
#html
<p class ="foo bar">...</p>
#css
#bar {background-color: yellow;}
#html
<p id="bar"> ... </p>
-요소와 클래스의 조합
p.bar{...}
-다중 클래스
.foo bar {...}
-아이디와 클래스의 조합
#foo.bar {...}
-단순 속성으로 선택
#css
p[class] {color:silver;}
p[class][id] {text-decoration: underline;}
#html
<p class="foo">Hello</p>
<p class="bar">CSS</p>
<p class="baz" id="title">HTML</p>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>css</title>
<style media="screen">
p[class] {color:silver;}
p[class][id] {text-decoration: underline;}
</style>
</head>
<body>
<p class="foo">Hello</p>
<p class="bar">CSS</p>
<p class="baz" id="title">HTML</p>
</body>
</html>
#css
p[class="foo"] {color:silver;}
p[id="title"] {text-decoration: underline;}
#html
<p class="foo">Hello</p>
<p class="bar">CSS</p>
<p class="baz" id="title">HTML</p>

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>css</title>
<style media="screen">
p[class="foo"] {color:silver;}
p[id="title"] {text-decoration: underline;}
</style>
</head>
<body>
<p class="foo">Hello</p>
<p class="bar">CSS</p>
<p class="baz" id="title">HTML</p>
</body>
</html>
-부분 속성값으로 선택
- [class~="bar"]: class 속성의 값이 공백으로 구분한 "bar" 단어가 포함되는 요소 선택
- [class^="bar"] : class 속성의 값이 "bar"로 시작하는 요소 선택
- [class$="bar"] : class 속성의 값이 "bar"로 끝나는 요소 선택
- [class*="bar"]: class속성의 값이 "bar"문자가 포함되는 요소 선택
div span {color: red;}
-> div요소의 자손, span 요소를 선택하는 선택자

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>css</title>
<style media="screen">
div span {color: red;}
</style>
</head>
<body>
<div>
<h1><span>1</span>2</h1>
<span>3</span>
</div>
<span>4</span>
<p>5</p>
</body>
</html>
div span {color: red;}

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>css</title>
<style media="screen">
div > span {color: red;}
</style>
</head>
<body>
<div>
<h1><span>1</span>2</h1>
<span>3</span>
</div>
<span>4</span>
<p>5</p>
</body>
</html>
div span {color: red;}

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>css</title>
<style media="screen">
div + span {color: red;}
</style>
</head>
<body>
<div>
<h1><span>1</span>2</h1>
<span>3</span>
</div>
<span>4</span>
<p>5</p>
</body>
</html>
:pseudo-class {
property: value;
}

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>css</title>
<style media="screen">
li:first-child{color:red;}
li:last-child{color:blue;} /*li:last-child는 띄어쓰기하면 안됨*/
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</body>
</html>
a:link {color: blue;}
a:visited {color: gray;}

▲ 방문전

▲ 방문후
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>css</title>
<style media="screen">
a:link {color: blue;}
a:visited {color: gray;}
</style>
</head>
<body>
<a href="https://naver.com/">네이버</a>
<a href="http://google.com/">구글</a>
<a href="https://daum.net">다음</a>
</body>
</html>
- :focus : 현재 입력 포커스를 갖고 있는 요소에 적용
- :hover :마우스 포인터가 위치해 있는 요소에 적용
- :active : 사용자 입력에 의해 활성화된 요소에 적용
a:focus {background-color: yellow;}
a:hover {font-weight: bold;}
a:active {color:red;}

▲focus

▲hover

▲active
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>css</title>
<style media="screen">
a:focus {background-color: yellow;}
a:hover {font-weight: bold;}
a:active {color:red;}
</style>
</head>
<body>
<a href="https://naver.com/">네이버</a>
<a href="http://google.com/">구글</a>
<a href="https://daum.net">다음</a>
</body>
</html>
- :before : 가장 앞에 요소를 삽입
<style media="screen"> p:before { color: red; content: "before가상요소를 사용한 내용" } </style>
- :after: 가장 뒤에 요소를 삽입
<style media="screen"> p:after { color: red; content: "after가상요소를 사용한 내용" } </style>
- :first-line: 요소의 첫번째 줄에 있는 텍스트
<style media="screen"> p:first-line { color: red; content: "first-line가상요소를 사용한 내용" } </style>
- first-letter : 블록 레벨 요소의 첫번째 문자
<style media="screen"> p:first-letter { color: red; content: "first-letter가상요소를 사용한 내용" } </style>
0,0,0,0
왼쪽이 높을수록 구체성이 높음
- 0,1,0,0 : 선택자에 있는 모든 id속성값
- 0,0,1,0 : 선택자에 있는 모든 class속성값, 기타 속성, 가상 클래스
- 0,0,0,1 : 선택자에 있는 모든 요소, 가상 요소
- 전체 선택자는 0,0,0,0을 갖는다.
조합자는 구체성에 영향을 주지 않는다.
p#page {color: red !important;}
!important : 모든 구체성을 무시하고 우선권을 가짐
우선 순위
1.사용자 !important 스타일
2.제작자 !important 스타일
- 제작자 스타일
- 사용자 스타일
- 사용자 에이전트 스타일
절대길이
- px : pixels
- pt : points
상대길이
- % : percentage
- em : font size of the element
- rem : font size of the root element
- vw : 1% of viewport's width
@media media queries{...}
-> media queries(미디어 쿼리문)가 참이면 실행된다.
- Media Types(미디어 타입)
-all,screen,print···
2.Media Features(미디어 특성)
-width(가로 뷰포트), orientation(미디어가 세로or가로)···
media_query_list(여러개의 미디어 쿼리로 이루어진 리스트로 작성 가능하며 쉼표를 이용해서 구분한다.)
: S* [media_query [ ',' S* media_query ]* ]? ;media_query
- A 형태 - 미디어 타입에 and를 이용해서 미디어 표현식을 붙일 수 있다. 미디어 타입 앞에는 only 또는 not 키워드가 올 수 있다. 미디어 표현식은 생략 가능하기 때문에 미디어 타입 단독으로 사용될 수 있다.
- B 형태 - 미디어 타입 없이 미디어 표현식이 바로 나올 수 있다.(미디어 타입이 명시되지 않으면 all로 간주)미디어 표현식은 and를 이용해서 계속해서 나올 수 있다.
: [ONLY | NOT]? S* media_type S* [ AND S* expression ]* | expression [ AND S* expression ]* ;expression : 미디어 표현식은 괄호로 감싸야 하며 특성 이름과 해당하는 값으로 이루어진다. 이름과 값은 : 기호로 연결한다. 값이 없이 특성 이름만으로도 작성할 수 있다.
: '(' S* media_feature S* [ ':' S* expr ]? ')' S* ;
[ a ] : a가 나올 수도 있고 나오지 않을 수도 있다
a | b : a or b
a? : a가 0번 나오거나 1번 나올 수 있다
a* : a가 0번 나오거나 2번 이상 계속 나올수 있다
media screen and (color)
(2) < link> 태그의 media 속성에 미디어 쿼리를 선언한다. 미디어 쿼리가 참이면 뒤에 css 파일 규칙이 적용된다.
<link rel="stylesheet" media="screen and (color)" href="example.css">
(3) CSS 파일 내부에 또는 < style> 태그 내부에 사용가능, @import문 뒤에 미디어 쿼리를 선언하면 된다.
@import url(example.css) screen and (color);