const darkModeToggle = document.getElementById('dark-mode-toggle'); const html = document.documentElement; // 检查系统主题 if (window.matchMedia('(prefers-color-scheme: dark)').matches) { html.classList.add('dark'); } // 监听系统主题变化 window.matchMedia('(prefers-color-scheme: dark)')...
<a href="#" class="text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 px-3 py-2 rounded-md text-sm font-medium"> 关于 </a> </div> </div> </div> <!-- 深色模式切换按钮 --> <button id="theme-toggle" class="rounded-lg p-2.5 text-gray-500 hover:...
<button class="bg-blue-500 hover:bg-blue-700 text-white p-2 rounded dark:bg-blue-700 dark:hover:bg-blue-800"> 点击切换深色模式 </button> </main> </div> <script> // 切换深色模式的JavaScript函数 function toggleDarkMode(e) { e.preventDefault(); document.documentElement.classList.toggle(...
Adding dark mode to tailwindcss with simple javascript and toggle button. Here is the demo CSS 0 0 0 0 Updated Nov 27, 2023 TailwindCSS-Simple-HTML Public Add tailwindcss in simple HTML project. CSS 0 0 0 0 Updated Oct 12, 2022 Custom-Fonts-TailwindCSS Public This repository ...
darkMode: "class", }; </script> <style> .toggle-checkbox:checked { right: 0; border-color: #68d391; } .toggle-checkbox:checked + .toggle-label { background: #68d391; } </style> </head> <body> <div class="container mx-auto mt-10 bg-white dark:bg-slate-900 rounded-xl px-...
RTL Toggle dark/light mode HTML Copy <button type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-...
Toggle tablet view Toggle mobile view Toggle RTL mode Toggle dark mode Copy to clipboard <divclass="w-48 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white"><buttonaria-current="true"type="button"class="w...
<button onclick="toggleTheme()" class=" flex bg-white w-12 h-12 md:w-16 md:h-16 flex-row justify-center items-center border-gray-300 dark:border-gray-600 dark:bg-[#121212] dark:text-white border rounded-full"> <i id="theme-toggler-moon" class="ri-moon-clear-line text-blue-80...
import{useState}from'react';functionApp(){const[darkMode,setDarkMode]=useState(false);consttoggleDarkMode=()=>{setDarkMode(!darkMode);};return(<div className={darkMode?'dark':''}><div className={'bg-white dark:bg-slate-700 h-full w-full absolute'}><button onClick={toggleDarkMode}>T...
<!-- src/index.html --><!-- 页面内容 --><buttonid="theme-toggle"class="bg-blue-500 text-white px-4 py-2 rounded">切换主题</button> 现在,当用户点击“切换主题”按钮时,网站会根据当前主题在“dark”类之间切换,实现主题切换功能。