inflearn logo
강의

Course

Instructor

Master TailwindCSS: From Portfolio to Admin!

TailwindCSS Dark Mode

tailwind.config.js 파일을 통해 다크 모드 설정시 적용이 되지 않습니다.

343

Droid

8 asked

0

[tailwind.config.js]

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ['./src/**/*.{html,js}'],
  darkMode: 'selector',
};

 

[practice-test.html]

<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Tailwind CSS</title>
    <script src="https://cdn.tailwindcss.com"></script>
  </head>
  <body class="bg-white dark:bg-gray-900 dark:text-white">
    <main
      class="container max-w-5xl mx-auto min-h-screen flex items-center justify-center"
    >
      <div class="flex flex-col items-center">
        <h1 class="font-extrabold text-3xl">Tailwind CSS 다크모드</h1>
        <p class="mt-4">이 페이지는 다크 모드를 지원합니다.</p>
        <button
          id="darkmode_btn"
          class="bg-blue-500 px-4 py-2 rounded-md text-white mt-4"
        >
          다크 모드 전환
        </button>

        <div
          class="px-10 py-6 bg-white rounded-md shadow-md mt-20 dark:bg-gray-800"
        >
          <p>이 박스는 다크 모드에서 배경이 어두운 색으로 변합니다.</p>
        </div>
      </div>
    </main>

    <script>
      document.querySelector('#darkmode_btn').addEventListener('click', () => {
        document.documentElement.classList.toggle('dark');
      });
    </script>
  </body>
</html>

 

tailwind.config.js 의 경로는 아래 스크린샷으로 첨부하였습니다.

image.png

 

 

제가 무슨 설정을 빠트린건지 명확히는 모르겠는데 <head> 태그 내부에 <script> 태그로 아래와 같이 설정하면 버튼을 클릭했을 때 다크모드와 원래 상태로 정상적으로 토글이 되는데 tailwind.config.js 로 설정만 하면 토글이 안되네요 모든 페이지에 다크모드를 설정하기 위해서는 tailwind.config.js 를 통해서 다크 모드 활성화를 하는 것이 좋을 것 같아서 질문 남깁니다! 좋은 강의 감사드립니다.

tailwind.config = { // darkMode: 'media', // 운영 체제의 모드에 맞게 설정 darkMode: 'selector', // 수동으로 설정 };

HTML/CSS javascript 반응형-웹 tailwindcss

Answer 1

0

gymcoding

CDN으로 tailwind 를 설치했을 경우에는 tailwind.config 설정을 해당 파일 안에 하셔야돼요~!

tailwind.config.js 파일은 tailwind intellisense를 위한 파일입니다.

 

10월 15일 삭제예정 강의 문의

0

36

1

강의가 중복됐어요

0

43

0

결제가 이루어지는 방식에 대한 문의

0

50

1

강의제목에 10/15일 삭제라고 나와있는데,

0

46

1

선생님 강의자료를 받을수 없어요! 메일보냈어요.

0

56

2

스크립트 영상 미일치

0

75

3

감정일기장 다이어리 필터 적용할때 컨텍스트를 Home에서 가져오는 특별한 이유가 궁금합니다.

0

54

2

강의 설명 중에 헷갈리는 것이 있네요

0

50

1

수업자료 관련 문의

0

65

3

1강 동영상 재생 오류

1

67

2

헤더에서 empty column이 삭제가 안되고, 헤더 레이아웃을 동영상처럼 선택하는 옵션이 안나오는데 어떻게 하나요?

0

40

1

tailwindcss v4.1 에서의 script 사용에 대해 궁금한 점이 있습니다.

1

153

1

확장 프로그램 설치 및 최적화 버전 문의

1

156

2

tailwindcss 와 ai tool

0

128

1

tailwindcss 4.1 docs에서는 container가 목록에서 안보이네요

0

124

2

quasar와 tailwind 조합에 관한 질문

0

138

1

실습에 사용되는 이미지

0

164

2

모바일 사이즈에 대해 질문있습니다.

0

121

1

nested 리스트일때 <ul> bullet 스타일 바꾸는 방법

0

249

2

via.placeholder.com 오류

0

917

2

빈 화면에서 tail 만 쳤을때 팝업도움말 나오게 하는 법 알려주세요.

0

166

2

수강평 이벤트

0

185

2

font-weight가 왜 적용이 안될까요?

0

469

3

스니펫 관련질문

0

174

1