css
CSS 탐구생활 : CSS의 적용방법과 우선순위
환상곰
2022. 6. 16. 02:04
반응형
1. CSS를 적용하는 여러가지 방법 |
(1) inline css
html 태그에 style속성을 이용해 직접 지정해주는 방법.
<div style="color: white">1</div>
(2) internal css
html 문서에서 head태그안에 style태그를 넣어 스타일을 지정해주는 방법.
<head>
<style>
.box {
background-color: blue;
}
</style>
</head>
(3) external css
외부 css파일을 html문서에 link를 통해 연결해주는 방법
<head>
<link rel="stylesheet" href="styles.css" />
</head>
-- 마크업과 스타일을 구분짓기 위해 external방식을 가장 많이 사용한다.
-- css 적용방법 우선순위
inline > internal > external
2. CSS 적용 우선순위 |
- 속성값 뒤에 !important -- 1순위
- inline style -- 2순위
- id 선택자 -- 3순위
- class 선택자, pseudo class(:first-child 같은) -- 4순위
- tag이름, 가상요소 선택자(::before 같은) -- 5순위
반응형