변수
Coddy HTML 여정의 Practical Frontend 섹션에 포함된 레슨 — 35개 중 17번째.
챌린지
쉬움우리는 Extreme Sports에 관한 페이지를 가지고 있습니다. 현재는 그다지 멋지거나 세련되어 보이지 않습니다. 앞으로 몇 차례의 레슨을 통해 우리가 배운 것들을 적용하여 단계별로 개선해 나갈 것입니다: CSS 변수, 모바일 퍼스트 전략, 그리고 몇 가지 테마 설정(theming) 기법들입니다.
최종적으로 페이지는 다음과 같은 모습이 될 수 있습니다 (정확한 색상과 스타일은 여러분의 선택에 달려 있습니다):

먼저 CSS 변수를 사용하여 Extreme Sports 페이지의 외관을 개선하는 것부터 시작하겠습니다.
여러분의 과제:
:root에 다음 변수들을 생성하세요:--primary-color--secondary-color--bg-color--text-color--card-bg
원하는 색상 값을 할당하세요.
- 스타일 전반에 이 변수들을 적용하세요:
<body>에--bg-color와--text-color를 설정하세요.<header>의 배경색으로--primary-color를 사용하세요.- description 및 fun facts 섹션의 배경색으로
--card-bg를 적용하세요. - 강조할 부분(예: 제목, 버튼 또는 강조 텍스트)에
--secondary-color를 사용하세요.
치트 시트
CSS 변수는 :root 선택자에 정의되며 스타일시트 전체에서 사용할 수 있습니다:
:root {
--primary-color: #value;
--secondary-color: #value;
--bg-color: #value;
--text-color: #value;
--card-bg: #value;
}CSS 변수를 var() 함수와 함께 사용하세요:
body {
background-color: var(--bg-color);
color: var(--text-color);
}
header {
background-color: var(--primary-color);
}직접 해보기
<!DOCTYPE html>
<html>
<head>
<title>Extreme Sports Adventures</title>
<style>
/* === Variables === */
body {
margin: 0;
line-height: 1.6;
}
header {
text-align: center;
padding: 2rem 1rem;
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
header h1 {
font-size: 2.2rem;
margin-bottom: 0.5rem;
}
header p {
margin: 0;
font-size: 1.1rem;
}
main {
max-width: 1200px;
margin: 2rem auto;
padding: 0 1rem;
display: flex;
flex-direction: column;
gap: 2rem;
}
.hero {
border-radius: 12px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.hero img {
width: 100%;
height: 350px;
object-fit: cover;
}
.description, .facts {
border-radius: 12px;
padding: 1.5rem;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.description h2, .facts h2 {
margin-top: 0;
}
.btn {
display: inline-block;
margin-top: 1rem;
padding: 10px 20px;
color: #fff;
text-decoration: none;
font-weight: bold;
border-radius: 8px;
transition: transform 0.3s, background-color 0.3s;
}
.btn:hover {
transform: scale(1.05);
}
ul {
padding-left: 20px;
}
</style>
</head>
<body>
<header>
<h1>Extreme Sports Adventures</h1>
<p>Feel the adrenaline with the world's most thrilling sports!</p>
</header>
<main>
<section class="hero">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/Parachuting_sport.jpg/960px-Parachuting_sport.jpg" alt="Skydiving">
</section>
<section class="description">
<h2>What is Extreme Sports?</h2>
<p>Extreme sports are activities that involve high risks and adrenaline. From skydiving and rock climbing to snowboarding and bungee jumping, these sports push your limits and give an unforgettable thrill.</p>
<a href="#" class="btn">Learn More</a>
</section>
<section class="facts">
<h2>Fun Facts</h2>
<ul>
<li>Skydiving reaches speeds over 120 mph during free fall.</li>
<li>Bungee jumping started as a ritual in Vanuatu called "land diving."</li>
<li>Rock climbing requires both strength and strategy.</li>
<li>Snowboarding evolved from surfing and skateboarding.</li>
</ul>
</section>
</main>
</body>
</html>