[Tailwind] Get started with Tailwindcss

In this lesson, we learn how to generate CSS utility classes from Tailwind's JavaScript config file. We set up a new project from scratch, install tailwind, generate a config file and build a simple gulp task that runs that file through PostCSS to generate the desired CSS output.

file through PostCSS via gulp.

 

Install:

npm i -D tailwindcss gulp gulp-postcss autoprefixer

 

Init a tailwind config file:

npx tailwind init
or
node_modules/.bin/tailwind init tailwind.js

It will generates a tailwind.js file.

 

Gulp setup:

复制代码
const gulp = require("gulp");
const postcss = require("gulp-postcss");
const tailwindcss = require("tailwindcss");

const PATHS = {
  css: "./src/styles.css",
  confing: "./tailwind.js",
  dist: "./"
};

gulp.task("css", () => {
  return gulp
    .src(PATHS.css)
    .pipe(postcss([tailwindcss(PATHS.config), require("autoprefixer")]))
    .pipe(gulp.dest(PATHS.dist));
});
复制代码

 

src/styles.css:

复制代码
/**
 * This injects Tailwind's base styles, which is a combination of
 * Normalize.css and some additional base styles.
 *
 * You can see the styles here:
 * https://github.com/tailwindcss/tailwindcss/blob/master/css/preflight.css
 *
 * If using `postcss-import`, use this import instead:
 *
 * @import "tailwindcss/preflight";
 */
 @tailwind preflight;

 /**
  * This injects any component classes registered by plugins.
  *
  * If using `postcss-import`, use this import instead:
  *
  * @import "tailwindcss/components";
  */
 @tailwind components;

 /**
  * Here you would add any of your custom component classes; stuff that you'd
  * want loaded *before* the utilities so that the utilities could still
  * override them.
  *
  * Example:
  *
  * .btn { ... }
  * .form-input { ... }
  *
  * Or if using a preprocessor or `postcss-import`:
  *
  * @import "components/buttons";
  * @import "components/forms";
  */

 /**
  * This injects all of Tailwind's utility classes, generated based on your
  * config file.
  *
  * If using `postcss-import`, use this import instead:
  *
  * @import "tailwindcss/utilities";
  */
 @tailwind utilities;

 /**
  * Here you would add any custom utilities you need that don't come out of the
  * box with Tailwind.
  *
  * Example :
  *
  * .bg-pattern-graph-paper { ... }
  * .skew-45 { ... }
  *
  * Or if using a preprocessor or `postcss-import`:
  *
  * @import "utilities/background-patterns";
  * @import "utilities/skew-transforms";
  */
复制代码

 

Run:

gulp css

It will generate a styles.css inside root folder.

 

index.html:

复制代码
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Abstract components with tailwind</title>
  <link rel="stylesheet" href="./styles.css">
</head>
<body>
  <h1 class="text-purple
          sm:text-grey-dark
          md:text-red-dark
          lg:text-orange-dark
          bg-pink-dark
          sm:bg-grey-lighter
          md:bg-teal-lighter
          lg:bg-indigo-lighter
          p-8 mt-8">Hello Tailwind!</h1>
</body>
</html>
复制代码

 

Those are repsonsive site related stuff, checkout the doc.

          sm:text-grey-dark
          md:text-red-dark
          lg:text-orange-dark
          bg-pink-dark
          sm:bg-grey-lighter
          md:bg-teal-lighter
          lg:bg-indigo-lighter

 

 

posted @   Zhentiw  阅读(890)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2017-04-10 [tmux] Copy and paste text from a tmux session
2017-04-10 [tmux] Customize tmux with tmux.conf
2017-04-10 [tmux] Zoom and resize to view a particular pane within tmux
2017-04-10 [tmux] Manage terminal workspaces using session naming
2017-04-10 [tmux] Reuse terminal workspaces using tmux sessions
2017-04-10 [tmux] Create collections of panes using tmux windows
2017-04-10 [tmux] Organize your terminal using tmux panes
点击右上角即可分享
微信分享提示