tailwind css_带有Tailwind CSS和Nuxt.js的深色和浅色主题

2023-11-01

tailwind css

Dark and light mode support has been a recent trend due to the impact on our eyesight caused by the time spent on devices. With Tailwind CSS and the proper Nuxt.js (Nuxt) modules, we can easily enable this feature, with the ability to customize each mode’s look and feel to your taste.

由于在设备上花费的时间对我们的视力造成了影响,因此对明暗模式的支持已成为最近的趋势。 借助Tailwind CSS和适当的Nuxt.js (Nuxt)模块,我们可以轻松启用此功能,并能够根据您的喜好自定义每种模式的外观。

TL; DR (TL;DR)

In short, you follow the simple steps below to enable dark/light mode with Tailwind CSS and the Nuxt color mode module:

简而言之,您可以按照以下简单步骤使用Tailwind CSS和Nuxt颜色模式模块启用暗/亮模式:

  • Install a Nuxt project using yarn create nuxt-app <project-name> and choose Tailwind CSS as a UI framework from the configuration selection. In case of an existing Nuxt project, run yarn add --dev @nuxtjs/tailwindcss and add the module @nuxtjs/tailwindcss to the list of buildModules in nuxt.config.js.

    使用yarn create nuxt-app <project-name>安装Nuxt项目,然后从配置选择中选择Tailwind CSS作为UI框架。 如果现有Nuxt项目,请运行yarn add --dev @nuxtjs/tailwindcss并将模块@nuxtjs/tailwindcss添加到buildModules中的nuxt.config.js列表中。

  • Install tailwindcss-dark-mode and @nuxtjs/color-mode.

    安装@nuxtjs/color-mode tailwindcss-dark-mode@nuxtjs/color-mode

  • Declare the use of tailwindcss-dark-mode as a plugin in the collection of plugins in tailwind.config.js. Do the same with @nuxtjs/color-mode by adding require('tailwindcss-dark-mode')() to the collection of plugins in nuxt.config.js.

    声明使用的tailwindcss-dark-mode的集合中的一个插件, pluginstailwind.config.js 。 通过在nuxt.config.jsplugins集合中添加require('tailwindcss-dark-mode')()来对@nuxtjs/color-mode进行相同的nuxt.config.js

  • Declare the use of dark mode variants per CSS utilities in the variants field in tailwind.config.js.

    tailwind.config.js中的variants字段中声明每个CSS实用工具使用深色模式变variants

  • Start assigning dark mode styles for elements using generated classes with syntax ${dark-mode-variant}:${normal-generated-class-for-css-property}.

    开始使用语法${dark-mode-variant}:${normal-generated-class-for-css-property}生成类为元素分配暗模式样式。

Too short to understand? Let’s go through slowly, shall we?

太短了以至于无法理解? 让我们慢慢来吧?

什么是Nuxt.js? (What Is Nuxt.js?)

Nuxt.js — or Nuxt for short — is a server-side rendering (SSR) framework based on Vue.js, and it offers developers:

Nuxt.js(简称为Nuxt)是基于Vue.js的服务器端渲染(SSR)框架,它为开发人员提供:

  • Flexibility — With a single codebase, developers have three build options to output their application, such as universal (pure SSR), single-page application (SPA), and static sites.

    灵活性-使用单个代码库,开发人员可以使用三种构建选项来输出其应用程序,例如通用(纯SSR),单页应用程序(SPA)和静态站点。
  • Organized code structure — A Nuxt app template comes with logical folder structures with a built-in router mechanism.

    有组织的代码结构-Nuxt应用程序模板带有带有内置路由器机制的逻辑文件夹结构。
  • Performance optimization — It has auto-code-splitting per page, keeping JavaScript bundled size relatively small for faster delivery.

    性能优化-它具有每页自动代码拆分功能,可将JavaScript绑定大小保持相对较小,以便更快地交付。

Also, Nuxt is surrounded by a well-maintained ecosystem — the Nuxt community, which provides lots of practical modules, plugins, and support to simplify the development process.

此外,Nuxt周围还有一个维护良好的生态系统-Nuxt社区,该社区提供了许多实用的模块,插件和支持,以简化开发过程。

什么是Tailwind CSS? (What Is Tailwind CSS?)

Tailwind CSS is a very efficient utility-first CSS framework. It offers developers a set of ready classes for different CSS utility properties, such as margin, padding, and font-size for styling.

Tailwind CSS是一个非常有效的实用程序优先CSS框架。 它为开发人员提供了一组用于不同CSS实用程序属性的就绪类,例如marginpaddingfont-size用于样式设置。

For example, to make the button above, it’s enough to apply the available classes accordingly:

例如,要使按钮上方,足以相应地应用可用的类:

<button
class="py-2 px-3 bg-green-500 rounded shadow-md text-white uppercase"
>
Button
</button>

In which:

其中:

  • py-—prefix for styles applied to padding-top and padding-bottom, similarly with px- for setting padding-left and padding-right properties

    py-适用于padding-toppadding-bottom样式的前缀,与px-类似,用于设置padding-leftpadding-right属性

  • bg- — prefer for background, followed by a color palette

    bg-偏爱background ,后跟调色板

  • rounded—set the value of border-radius

    rounded -设置border-radius的值

  • shadow — —prefix for box-shadow

    shadow — box-shadow前缀

  • text-—prefix for any text-related CSS properties (font-size and color), like text-white for setting the color to white

    text-任何与文本相关CSS属性( font-sizecolor )的前缀,例如text-white用于将color设置为white

We can also combine different classes to create a custom class, such as the .btn class from the classes used in the example above. The significant advantage of Tailwind CSS is that it allows developers to write less (and less repetitive) CSS code for utilities, and hence keep the overall design consistent, with @apply.

我们还可以组合不同的类来创建自定义类,例如上例中使用的类中的.btn类。 Tailwind CSS的显着优势在于,它允许开发人员为实用程序编写更少(和更少重复)CSS代码,从而使总体设计与@apply保持一致。

.btn {
       
@apply py-2 px-3 bg-green-500 rounded-md shadow-md text-white uppercase;
}

Tailwind CSS will generate the related styles into a single rule set for the .btn class selector, as seen in the browser:

Tailwind CSS会将相关样式生成为.btn类选择器的单个规则集,如浏览器所示:

By using PurgeCSS in the back, Tailwind CSS offers the ability to remove unused classes in our application and thus optimize the size of CSS ne

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

tailwind css_带有Tailwind CSS和Nuxt.js的深色和浅色主题 的相关文章

随机推荐

  • Log4J2在Web工程下日志无法写入文件的问题

    接触Log4J不久 之前在Java工程测试学习的 一切正常 前几天在做一个JSP的案子 Web工程下 同样的配置文件 却写不到文件 在控制台日志正常输出 Web工程下 在Java类main方法中测试 也可以正常写入文件 控制台也是正常 经过
  • 互动直播的技术细节和解决方案实践经验谈

    目录 1 互动直播背景 2 连麦流程 功能与技术指标 2 1 连麦的业务流程 2 2 互动直播的功能 2 3 技术指标 2 4 应用领域 3 主流的技术方案 3 1 互动直播技术领域 3 2 主流的技术方案 3 2 1 基于RTMP技术的连
  • 背调小计

    新员工入职前的背调 了解下 附上链接 https zhuanlan zhihu com p 33248594
  • (2021-8-17) Qt5 中自带的几种button控件简介

    本节参考正点原子qt教程 1 按钮简介 在Qt中最常用的控件应该就是按钮了 点击按钮 即可发送信号 触发响应事件 实现人机交互 在Qt中内置了六中按钮控件 1 QPushButton QPushButton 继承 QAbstractButt
  • SQL server无法启动服务,提示“错误1069: 由于登录失败而无法启动服务”

    转自 http www 111cn net database mssqlserver 52624 htm 今天在启动sqlserver2008时碰到了遇到SQL server无法启动服务 提示 错误1069 由于登录失败而无法启动服务 提示
  • C语言字符串完成大小写转换

    4 编写一个程序 可以一直接收键盘字符 如果是小写字符就输出对应的大写字符 如果接收的是大写字符 就输出对应的小写字符 如果是数字不输出 此题第一步需要遍历整个输入字符串 第二部完成循环判断赋值将符合条件的值赋值到新的字符串数组中即可 de
  • 线程的五种状态

    1 新建状态 New 创建一个新的线程对象 2 就绪状态 Runnable 线程创建对象后 其他线程调用start 方法 该线程处于就绪状态 资源已经准备就绪 等待CPU资源 3 运行状态 Running 处于就绪状态的线程获取到CPU资源
  • javascript 琐碎知识点1

    1 Javascript是一种基于对象和事件驱动 并具有安全性能的脚本语言 2 Javascript的特点 1 一种脚本编写语言 它的基本结构与C C 十分类似 但它不像这些语言需要先编译 而是在程序运行的过程中被逐行地进行解释 2 基于对
  • Redis分布式锁的实现原理看这篇就够了~

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 一 写在前面 现在面试 一般都会聊聊分布式系统这块的东西 通常面试官都会从服务框架 Spring Cloud Dubbo 聊起 一路聊到分布式事务 分布式锁 ZooKeep
  • ffmpeg编译iOS的.a库

    一 编译环境 系统 本人编译是在mac下的 此方法同样适用于linux yasm 接下来介绍yasm的安装 二 yasm的安装 打开终端 不用管当前目录是在哪 直接执行 brew install yasm 如果提示brew not foun
  • VTM遇到的问题集锦

    文章目录 一 待更新中 1 配置好VTM后 并在调试界面输入命令参数后 点击运行 既不报错 也没有任何结果 2 未加载符号文件 3 编码闪退问题 4 VTM AI编码帧数为总帧数八分之一 一 待更新中 1 配置好VTM后 并在调试界面输入命
  • 因果分析系列4--基于python的因果图模型学习

    因果分析系列4 因果图模型 1 因果图模型介绍 2 基于python绘制因果图模型 3 三种常见的因果图结构 3 1 链结构 chain 3 2 叉结构 fork 3 3 对撞结构 collider 4 巩固思考示例 在上一节中 介绍了因果
  • NodeJS优缺点及适用场景讨论

    http www xprogrammer com 159 html 概述 NodeJS宣称其目标是 旨在提供一种简单的构建可伸缩网络程序的方法 那么它的出现是为了解决什么问题呢 它有什么优缺点以及它适用于什么场景呢 本文就个人使用经验对这些
  • MongoDB设置自增字段

    在使用mongoDB数据库的时候有时候想要对数据库空的数字字段直接进行加减操作 可以用到 inc来实现 比如我想要把网站访问量的数据存到mongoDB数据库中 每次进入网站都可以把该数据进行一次 1操作 通过node js的mongoose
  • 【千律】C++基础:通过文件指针获取文件大小(字节数)

    include
  • Idea导入Eclipse项目

    文章目录 1 选择从已有文件导入 2 配置依赖 3 配置tomcat 在学习过程中经常遇到 eclipse 开发的项目 但是由于和 idea 配置有差异不能直接运行 需要做一些修改 1 选择从已有文件导入 使用 idea 导入文件 注意这里
  • vs2019 MFC 如何在框架类中实现添加一个按钮button

    首先 在框架类CMainFrame中添加一个CButton m btn的成员 然后 在框架类CMainFrame中OnCreate 函数最后添加创建button的函数并显示button 注意 在创建button函数create中如果使用了W
  • 安装VTK8.2.0-win 实际操作

    Windows下安装VTK8 2 0 1 依赖 VS2017 Qt5 cmake 2 前期准备 2 1 访问vtk官方下载VTK8 2 0源码 VTK源码下载地址 https vtk org download 2 2 配置环境变量 配置CM
  • Cookie与Session之(简单购物车示例)

    Cookie 实际上是一小段的文本信息 客户端请求服务器 如果服务器需要记录该用户状态 就使用 response 向客户端浏览器颁发一个 Cookie 客户端浏览器会把 Cookie 保存起来 当浏览器再请求该网 站时 浏览器把请求的网址连
  • tailwind css_带有Tailwind CSS和Nuxt.js的深色和浅色主题

    tailwind css Dark and light mode support has been a recent trend due to the impact on our eyesight caused by the time sp