a
태그에서는 link
로 기본 색상 변경, active
로 클릭 된 색상 변경, hover
로 커서 활성화 상태 색상 변경HTML 문서
<body>
<a href="https://www.naver.com">네이버</a>
</body>
CSS 문서
a:link {
color: red;
}
a:active {
color: blue;
}
a:hover {
color: pink;
}
input
태그에서는 focus
로 글 활성화 상태 테두리 변경HTML 문서
<body>
<input type="text">
</body>
CSS 문서
input:focus {
border: solid 10px red;
}
first-child
로 첫번째 태그 변경, last-child
로 마지막 태그 변경nth-child(n)
로 n번째 태그 변경,nth-child(2n-1)
짝수 변경은 nth-child(2n)
HTML 문서
<body>
<ul>
<li>메뉴1</li>
<li>메뉴2</li>
<li>메뉴3</li>
<li>메뉴4</li>
<li>메뉴5</li>
<li>메뉴6</li>
</ul>
</body>
CSS 문서
li:first-child {
color: red;
}
li:last-child {
color: blue;
}
li:nth-child(2) {
color: gray;
}
before
,after
HTML 문서
<body>
<ul>
<li>로그인</li>
<li>회원가입</li>
<li>회사소개</li>
<li>고객센터</li>
</ul>
</body>
CSS 문서
li:before {
content: "***";
}
li:after {
content: "---";
}
HTML 문서
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<h1>Hello World</h1>
</body>
CSS 문서
h1 {
color: red;
}
../
라는 경로를 넣어야 폴더 밖으로 나와짐img
태그를 쓸 때는 그대로 index.html 파일 기준HTML 문서
<body>
<div></div>
<img src="img/icon.png">
</body>
CSS 문서
div {
width: 300px;
height: 300px;
background-image: url(../img/icon.png);
}
HTML 문서
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<ul class="friends-lists">
<li class="friends-list">
<a href="#">
<img src="https://via.placeholder.com/50" class="friend-thumbnail">
<div class="friend-info">
<h3 class="friend-name">김민호</h3>
<span class="friend-intro">Minho Kim</span>
</div>
</a>
</li>
<li class="friends-list">
<a href="#">
<img src="https://via.placeholder.com/50" class="friend-thumbnail">
<div class="friend-info">
<h3 class="friend-name">박지연</h3>
<span class="friend-intro">다정한 사람</span>
</div>
</a>
</li>
<li class="friends-list">
<a href="#">
<img src="https://via.placeholder.com/50" class="friend-thumbnail">
<div class="friend-info">
<h3 class="friend-name">한성은</h3>
<span class="friend-intro">헤헷</span>
</div>
</a>
</li>
</ul>
</body>
</html>
CSS 문서
.friends-lists {
list-style: none;
}
.friends-lists .friends-list a {
color: #000000;
text-decoration: none;
}
.friends-lists .friends-list a .friend-thumbnail {
border: solid 2px gray;
border-radius: 20px;
}
.friends-lists .friends-list a .friend-info .friend-name {
font-size: 20px;
color: #000000;
}
.friends-lists .friends-list a .friend-info .friend-intro {
font-size: 15px;
color: #c8c8c8;
}
line-height
을 사용하여 적용HTML 문서
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<ul class="living-lists">
<li class="living-item">
<a href="#">
<img src="https://via.placeholder.com/170x114" class="living-thumbnail">
<div class="living-info">
<span class="type">리빙</span>
<h3 class="title">30평대 아파트, 따뜻한 느낌의 침실</h3>
<p class="paragraph">Nice to meet you Nice to meet you Nice to meet you Nice to meet you Nice to meet you</p>
<div class="date-wrap">
<span class="source">유닠</span>
<span class="date">3개월 전</span>
</div>
</div>
</a>
</li>
<li class="living-item">
<a href="#">
<img src="https://via.placeholder.com/170x114" class="living-thumbnail">
<div class="living-info">
<span class="type">리빙</span>
<h3 class="title">아이있는 집 주방 1년 간의 소소한 변화</h3>
<p class="paragraph">Nice to meet you Nice to meet you Nice to meet you Nice to meet you Nice to meet you</p>
<div class="date-wrap">
<span class="source">miju</span>
<span class="date">1개월 전</span>
</div>
</div>
</a>
</li>
</ul>
</body>
</html>
CSS 문서
.living-lists {
list-style: none;
}
.living-lists .living-item a {
color: #000000;
text-decoration: none;
}
.living-lists .living-item .living-info .type {
color: #c08d31;
font-weight: 700;
font-size: 12px;
}
.living-lists .living-item .living-info .title {
font-size: 13px;
color: #000000;
}
.living-lists .living-item .living-info .paragraph {
font-size: 13px;
color: #404040;
line-height: 20px;
}
.living-lists .living-item .living-info .date-wrap .source,
.living-lists .living-item .living-info .date-wrap .date {
font-size: 12px;
color: #505050;
}
.living-lists .living-item .living-info .date-wrap .date {
color: gray;
}
.living-lists .living-item .living-info .date-wrap .date:before {
content: '- ';
}
.living-lists .living-item:hover {
background-color: pink;
}
.living-lists .living-item a:hover .living-info .title {
text-decoration: underline;
}