전체 선택자
태그 선택자
아이디 선택자
클래스 선택자
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS3 Selector Basic</title>
<style>
* {
color: yellow;
}
h1 {
color: red;
}
p {
color: blue;
}
</style>
</head>
<body>
<h1>제목 글자</h1>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dicta facilis
porro natus quisquam tempore iste eveniet debitis est, incidunt et! Quae,
vel voluptatum cumque repudiandae delectus repellat similique pariatur
nesciunt!
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus iusto
rem eos nisi rerum recusandae optio a! Nisi autem illum adipisci, sit
possimus corrupti laudantium necessitatibus at sequi ipsam distinctio.
</p>
</body>
</html>
여러 태그에 동일 스타일 적용? 태그 선택자를 쉼표로 연결
중앙 정렬
#header {
width: 800px; margin: 0 auto;
background: red;
}
#aside {
width: 200px; float: left;
background: blue;
}
float: left;
id의 중복 사용
기본 선택자(클래스) 다음으로 많이 쓰는 선택자
부모 자식 관계를 보고 선택
<style>
/* table에서 <tbody> 생략 시, 코드에서는 안 보여도 개발자 모드 보면 자동 추가되어 있음 */
/* 그래서 table > tr > th로 작성시 스타일이 적용 안 됨 */
/* table > tbody > tr > th로 작성 or table tr > th 둘다 출력값은 같음 */
table tr > th {
color: red;
}
</style>
반응 선택자
상태 선택자
input:enabled구조 선택자
first-child, last-child
nth-child(수열), nth-last-child(수열)
수직으로 나오는 리스트를 수평으로 바꾸는 방법 : float, flex
<style>
ul {
overflow: hidden;
/* 초과된 내용 숨김 */
}
li {
list-style: none;
/* 불릿 포인트(동그라미) 없애기 */
float: left;
/* 수평 배치, 왼쪽으로 붙여라 */
padding: 15px;
/* 경계선과 컨텐츠 사이의 여백처리 */
}
li:first-child {
border-radius: 10px 0 0 10px;
}
li:last-child {
border-radius: 0 10px 10px 0;
}
li:nth-child(2n) {
background-color: #ff0003;
}
li:nth-child(2n + 1) {
background-color: #800000;
}
</style>
메뉴를 만들 때 많이 등장하는 패턴이다
키워드 단위
크기 단위
색상 단위
url
<style>
#header {
width: 800px;
margin: 0 auto;
background: red;
}
#wrap {
width: 800px;
margin: 0 auto;
}
#aside {
width: 200px;
float: left;
background: blue;
}
#content {
width: 600px;
float: left;
background: green;
}
</style>
<body>
<div id="header">
<h1>#header 태그</h1>
</div>
<div id="wrap">
<div id="aside">
<h1>#aside 태그</h1>
</div>
<div id="content">
<h1>#content 태그</h1>
</div>
</div>
</body>
<style>
input[type='text'] {
background-color: red;
}
input[type='password'] {
background-color: blue;
}
</style>
<body>
<form>
<input type="text" />
<input type="password" />
</form>
</body>
<!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>
#header h1 {
color: red;
}
#section h1 {
color: orange;
}
</style>
</head>
<body>
<div id="header">
<h1 class="title">Lorem ipsum</h1>
<div id="nav">
<h1>Navigation</h1>
</div>
</div>
<div id="section">
<h1 class="title">Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</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>
#header > h1 {
color: red;
}
#section > h1 {
color: orange;
}
</style>
</head>
<body>
<div id="header">
<h1 class="title">Lorem ipsum</h1>
<div id="nav">
<h1>Navigation</h1>
</div>
</div>
<div id="section">
<h1 class="title">Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</body>
</html>
<style>
h1:hover {
color: red;
}
h1:active {
color: blue;
}
</style>
margin
padding
border
width, height
태그가 화면에 보이는 방식을 지정
display 속성
배경 이미지나 색상 지정
body {
/* 각각의 그림을 레이어 */
background-image: url('BackgroundFront.png'),
url('BackgroundBack.png');
}글자 크기
글꼴
글자 스타일(기울기 등)
글자 굵기
글자 정렬
링크 글자의 밑줄
text-decoration: none;<style>
.box {
width: 100px;
height: 100px;
/* position: absolute; */
}
.box:nth-child(1) {
background-color: red;
}
.box:nth-child(2) {
background-color: green;
}
.box:nth-child(3) {
background-color: blue;
}
</style>
<style>
.box {
width: 100px;
height: 100px;
position: absolute;
}
.box:nth-child(1) {
background-color: red;
left: 10px;
top: 10px;
}
.box:nth-child(2) {
background-color: green;
left: 50px;
top: 50px;
}
.box:nth-child(3) {
background-color: blue;
left: 90px;
top: 90px;
}
</style>
position: absolute; 준 경우요소의 고정 위치와 상대 위치 지정
absolute 사용법
그림자 속성
그레이디언트 속성
<!DOCTYPE html>
<html lang="en">
<head>
<title>relative는 기준이 나</title>
<style>
div {
display: inline-block;
/* border: 1px solid red; */
width: 50px;
height: 50px;
background-color: red;
color: white;
text-align: center;
}
#down:hover {
position: relative; -> 자기 자신의 원래 위치(static 위치)를 기준으로 이동함
left: 25px; -> 왼쪽에서 오른쪽으로 25px 이동, 왼쪽에 공간이 생김!
/* right: -25px; */
top: 25px;
background-color: blue;
}
#up:hover {
position: relative;
right: 25px;
bottom: 25px;
background-color: blue;
}
</style>
</head>
<body>
<h3>상대배치, relative</h3>
<hr />
<div>T</div>
<div id="down">h</div>
<div>a</div>
<div>n</div>
<div id="up">k</div>
<div>s</div>
</body>
</html>
visibility: hidden;

display: none;

숨기면 이벤트 발생이 안 됨
span {
visibility: hidden;
}
span:hover {
visibility: visible;
color: red;
}
=> 해결 방법
<!DOCTYPE html>
<html lang="en">
<head>
<title>span이 아닌 li를 hover</title>
<style>
span {
visibility: hidden;
}
/* 이렇게 하면 블럭 단위로 잡혀서 빈 공간을 호버해도 글씨가 나타나게 됨 */
li:hover span {
visibility: visible;
color: red;
}
</style>
</head>
<body>
<h3>다음 빈 곳에 숨은 단어?</h3>
<hr />
<ul>
<li>I (<span>love</span>) you.</li>
<li>CSS is Cascading (<span>Style</span>) Sheet.</li>
<li>응답하라 (<span>1988</span>).</li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>2개의 span</title>
<style>
#item span {
/* opacity: 0; */
/* display: none; */
visibility: hidden;
}
/* <span>을 하나 더 걸어줘서 해결하는 방법 or opacity: 0, 1으로 주는 방법도 있음 */
#item:hover span {
visibility: visible;
color: red;
}
</style>
</head>
<body>
<h3>다음 빈 곳에 숨은 단어?</h3>
<hr />
<ul>
<li>
I (<span id="item"><span>love</span></span
>) you.
</li>
<li>
CSS is Cascading (<span id="item"><span>Style</span></span
>) Sheet.
</li>
<li>
응답하라 (<span id="item"><span>1988</span></span
>).
</li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<style>
img {
float: left; -> 이미지를 왼쪽으로 띄움
width: 100px;
height: 100px;
}
#container::after { -> 부모 요소(#container)가 float된 요소를 감싸도록 설정
content: '';
display: block;
clear: both; -> float로 인해 부모 높이가 사라지는 문제 해결
}
</style>
</head>
<body>
<div id="container">
<img src="BackgroundBack.png" />
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nihil nulla
nostrum expedita deserunt, sequi rerum porro, veniam sed repellat
veritatis iusto optio quas illum soluta, possimus molestiae pariatur
labore? Nostrum!
</p>
</div>
<p> -> container 바깥의 p 태그들 → 새로운 단락들이 추가됨
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nihil nulla
nostrum expedita deserunt, sequi rerum porro, veniam sed repellat
veritatis iusto optio quas illum soluta, possimus molestiae pariatur
labore? Nostrum!
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nihil nulla
nostrum expedita deserunt, sequi rerum porro, veniam sed repellat
veritatis iusto optio quas illum soluta, possimus molestiae pariatur
labore? Nostrum!
</p> -> clear: both;가 적용되어 container 바깥의 문장이 이미지 영향을 받지 않고 정상적으로 배치됨
</body>
</html>