스타일시트 언어
<head>요소 안어서 <style>태그를 사용하여 정의<style>요소 내부에 CSS 속성을 직접 입력HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Website</title>
<style>
/* 전체 문서의 배경색과 글꼴 지정 */
body {
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}
/* 제목의 글자색 지정 */
h1 {
color: #333;
}
/* 문단의 글자 크기 지정 */
p {
font-size: 16px;
}
</style>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a sample paragraph with some text.</p>
</body>
</html>
<link>요소에 href 속성으로 css파일명을 입력하면 HTML 문서와 외부에 있는 CSS 파일이 연결HTML
<link rel="stylesheet" href="styles.css">
<link> css/styles.css 처럼 경로를 적음HTML
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Website</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a sample paragraph with some text.</p>
</body>
</html>
CSS
/* style.css */
/* 전체 문서의 배경색과 글꼴 지정 */
body {
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}
/* 제목의 글자색 지정 */
h1 {
color: #333;
}
/* 문단의 글자 크기 지정 */
p {
font-size: 16px;
}
선택자(Selectors)
CSS
/* 선택자 예제 */
body {
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}
h1 {
color: #333;
}
p {
font-size: 16px;
}
<body> 요소, <h1> 요소, <p> 요소를 선택하는 선택자입니다. 같은 요소가 두 개 이상 있어서 각각의 스타일을 지정하고 싶을 때는 id, class 선택자를 사용합니다. .클래스이름HTML
<p class="highlight paragraph">이 문장은 강조되고 특별한 스타일이 적용됩니다.</p>
CSS
.highlight {
background-color: yellow;
}
.paragraph {
font-size: 16px;
}
HTML
<div id="header">
<!-- 내용 -->
</div>
CSS
#header {
background-color: #333;
color: #fff;
font-size: 24px;
}
CSS
/* 속성과 값 예제 */
body {
background-color: #f4f4f4; /* 배경색 지정 */
font-family: Arial, sans-serif; /* 글꼴 지정 */
}
h1 {
color: #333; /* 글자색 지정 */
}
p {
font-size: 16px; /* 글자 크기 지정 */
}
실습


