How To Use Tailwind CSS With A Plain PHP Project

DDD
Release: 2024-09-19 02:18:08
Original
1041 people have browsed it

(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'),
  ],
};
Copy after login
  • Create a folder called src and a styles.css file with this code:
@tailwind base;
@tailwind components;
@tailwind utilities;
Copy after login
  • Add a build script to your package.json:
  "scripts": {
    "build:css": "npx postcss src/styles.css -o public/styles.css"
  },
Copy after login
  • 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">
Copy after login
  • 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: [],
}
Copy after login

Happy Coding Folks!

The above is the detailed content of How To Use Tailwind CSS With A Plain PHP Project. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!