1. 다크모드 버튼 클릭시 dark 클래스 추가 - 스크립트로 제어 2. 다크모드 버튼 아이콘 이미지는 백그라운드 이미지로 제어 - 클릭 시 css로 아이콘 변경 가능 3. root 속성으로 작성된 css를 활용 - 다크모드에서 일괄 수정 4. 아이콘 이미지의 경우(SVG) 반전 효과 사용 : css의 filter:invert(1) 속성 활용
위의 사항들을 순서로 하여 마크업과 CSS 제작을 진행해 봅니다.
최종 view 모습 (하단에서 확인)
라이트 모드
라이트 모드
다크모드
다크모드
HTML
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
<link href="https://cdn.jsdelivr.net/npm/reset-css@5.0.2/reset.min.css" rel="stylesheet">
<link rel="stylesheet" as="style" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable.min.css" />
</head>
<body>
<div class="main">
<div class="gnb">
<div class="user-wrap">
<div class="mode" onclick="toggleTheme()">
<div class="mode-change" alt="night아이콘"></div>
</div>
<div class="user">
<b>SU</b>
</div>
</div>
</div>
<div class="wrap">
<div class="contents">
<div class="txt">
<div class="txt-sample">
<div class="bd-wrap">
<div class="bd-row">
<div class="bd">
<div class="bd-tit">What is Lorem Ipsum?</div>
<div class="bd-txt">
<ul class="ul">
<li>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</li>
</ul>
</div>
</div>
<div class="bd">
<div class="bd-tit">Why do we use it?</div>
<div class="bd-txt">
<ul class="ul">
<li>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Javascript
function toggleTheme() {
document.documentElement.classList.toggle('dark');
}
댓글