首页 > 后端开发 > php教程 > How To Use Tailwind CSS With A Plain PHP Project

How To Use Tailwind CSS With A Plain PHP Project

DDD
发布: 2024-09-19 02:18:08
原创
1095 人浏览过

(Image Source)

How To Use Tailwind CSS With A Plain PHP Project

To start using Tailwind CSS with your plain PHP project, you can install Tailwind CSS in your project. This is how:

  • Run npm init -y in the terminal.

  • Install Tailwind dependencies: npm install tailwindcss postcss autoprefixer

  • Generate Tailwind configuration file: npx tailwindcss init

  • Create a postcss.config.js file and add this code:

module.exports = {
  plugins: [
    require('tailwindcss'),
    require('autoprefixer'),
  ],
};
登录后复制
  • Create a folder called src and a styles.css file with this code:
@tailwind base;
@tailwind components;
@tailwind utilities;
登录后复制
  • Add a build script to your package.json:
  "scripts": {
    "build:css": "npx postcss src/styles.css -o public/styles.css"
  },
登录后复制
  • Run npm run build:css in the terminal.

  • Include a link to the public/styles.css in your page’s file (example: index.php):

<link href="./public/styles.css" rel="stylesheet">
登录后复制
  • Make sure you run npm run build:css after making changes.

  • Also, make sure your tailwind.config.js includes the paths to your .php and .html files:

/** @type {import('tailwindcss').Config} */
module.exports = {
  darkMode: 'class', // or 'media'
  content: [
    "./**/*.php",
    "./**/*.html"
  ],
  theme: {
    extend: {
...
    }
  },
  plugins: [],
}
登录后复制

Happy Coding Folks!

以上是How To Use Tailwind CSS With A Plain PHP Project的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:dev.to
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板