当前位置: 首页 > news >正文

nuxtjs3 使用tailwindcss做自适应

步骤 1: 安装 Tailwind CSS

npm install tailwindcss postcss autoprefixer @nuxtjs/tailwindcss

步骤 2: 配置 Tailwind CSS
这将生成一个 tailwind.config.js 文件。

npx tailwindcss init

步骤 3: 配置 nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({compatibilityDate: '2024-04-03',devtools: { enabled: true },// 配置网站头部信息,包括 logo 和 faviconapp: {head: {link: [{ rel: "icon", type: "image/x-icon", href: "/logo.ico" }],}},devServer: {host: '0.0.0.0',port: 3000},css: ['~/assets/css/tailwind.css','~/assets/css/style.css'],site: { //https://nuxtseo.com/url: 'http://localhost:3000',name: 'name',description: '科技、创新、服务、物联网、iot、智能物联平台', // The description of your site, used in the meta tags.},// Vite 配置vite: {css: {postcss: {plugins: [require('tailwindcss'),require('autoprefixer'),],},},},modules: ['@nuxtjs/seo','@nuxtjs/tailwindcss']
})

步骤 4: 创建 Tailwind CSS 文件
在 assets/css 目录下创建 tailwind.css 文件,并添加 Tailwind 的基础指令:

/* assets/css/tailwind.css *//* Import Tailwind's base styles */
@import 'tailwindcss/base';/* Import Tailwind's component styles */
@import 'tailwindcss/components';/* Import Tailwind's utility styles */
@import 'tailwindcss/utilities';/* Add any custom global styles here */

步骤 5: 配置 Tailwind CSS
在 tailwind.config.js 文件中,你可以配置 Tailwind 的响应式断点和自定义主题。例如:

// tailwind.config.js
module.exports = {content: ["./pages/**/*.{vue,js,ts,jsx,tsx}","./components/**/*.{vue,js,ts,jsx,tsx}","./layouts/**/*.{vue,js,ts,jsx,tsx}","./plugins/**/*.{js,ts}","./nuxt.config.{js,ts}",],theme: {extend: {colors: {primary: '#3490dc',secondary: '#ffed4a',},fontFamily: {sans: ['Helvetica', 'Arial', 'sans-serif'],},// Add custom breakpoints if neededscreens: {'sm': '640px','md': '768px','lg': '1024px','xl': '1280px','2xl': '1536px',},},},plugins: [],
}

步骤 6: 使用 Tailwind CSS 类

<template><div class="container mx-auto p-4"><header class="bg-primary text-white p-4 text-center"><h1 class="text-2xl md:text-4xl">Welcome to My Website</h1></header><main class="my-8"><section class="bg-gray-100 p-4 rounded-lg shadow-md"><h2 class="text-xl">Responsive Section</h2><p class="text-base md:text-lg">This is a responsive section that adjusts based on screen size.</p></section></main><footer class="bg-secondary text-center p-4"><p class="text-sm">Footer content goes here</p></footer></div>
</template><script setup>
// Your script logic here
</script><style scoped>
/* Add any scoped styles here */
</style>
http://www.lryc.cn/news/463886.html

相关文章:

  • 数据资产目录构建方法与应用
  • 【Python爬虫实战】从文件到数据库:全面掌握Python爬虫数据存储技巧
  • 断其一指,无惧!ProFusion3D: 相机或者激光失效仍高效的多传感器融合3D目标检测算法
  • CCS字体、字号更改+CCS下载官方链接
  • YOLO11改进|注意力机制篇|引入SEAM注意力机制
  • 简历修订与求职经历 - Chap04
  • 鸿蒙开发案例:推箱子
  • mysql--表的约束
  • Ubuntu 上安装 docker 并配置 Docker Compose 详细步骤
  • MySQL去除空白字符(如非标准空格、制表符等)
  • 2063:【例1.4】牛吃牧草
  • QT开发:深入掌握 QtGui 和 QtWidgets 布局管理:QVBoxLayout、QHBoxLayout 和 QGridLayout 的高级应用
  • Bootstrapping、Bagging 和 Boosting
  • 板块龙头公司
  • Java项目-基于Springboot的招生管理系统项目(源码+说明).zip
  • 使用 MongoDB 构建 AI:利用实时客户数据优化产品生命周期
  • 【React】React18核心源码解读
  • 部署私有仓库以及docker web ui应用
  • DAY57WEB 攻防-SSRF 服务端请求Gopher 伪协议无回显利用黑白盒挖掘业务功能点
  • 光盘刻录大文件时分卷操作
  • Kafka系列之:生产者性能调优
  • 【linux】进程创建与进程终止
  • QT的文件操作类 QFile
  • java项目篇-用户脱敏展示
  • 《C++计算引擎:驱动高效计算的强大动力》
  • Linux的hadoop集群部署
  • 请问:ESModule 与 CommonJS 的异同点是什么?
  • 【数据结构与算法】力扣 59. 螺旋矩阵 II
  • HarmonyOS Next模拟器异常问题及解决方法
  • 求最大公约数(c语言)