Skip to content

docs: update Tailwind CSS guide for v4 #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 11 additions & 39 deletions docs-src/0.6/src/cookbook/tailwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

You can style your Dioxus application with whatever CSS framework you choose, or just write vanilla CSS.


One popular option for styling your Dioxus application is [Tailwind](https://tailwindcss.com/). Tailwind allows you to style your elements with CSS utility classes. This guide will show you how to setup tailwind CSS with your Dioxus application.
One popular option for styling your Dioxus application is [Tailwind](https://tailwindcss.com/). Tailwind allows you to style your elements with CSS utility classes. This guide will show you how to setup Tailwind CSS with your Dioxus application.

## Setup

Expand All @@ -13,51 +12,24 @@ One popular option for styling your Dioxus application is [Tailwind](https://tai
cargo install dioxus-cli
```

2. Install npm: [https://docs.npmjs.com/downloading-and-installing-node-js-and-npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
3. Install the tailwind css cli: [https://tailwindcss.com/docs/installation](https://tailwindcss.com/docs/installation)
4. Initialize the tailwind css project:

```bash
npx tailwindcss init
```

This should create a `tailwind.config.js` file in the root of the project.

5. Edit the `tailwind.config.js` file to include rust files:

```js
module.exports = {
mode: "all",
content: [
// include all rust, html and css files in the src directory
"./src/**/*.{rs,html,css}",
// include all html files in the output (dist) directory
"./dist/**/*.html",
],
theme: {
extend: {},
},
plugins: [],
}
```
2. Install NPM: [https://docs.npmjs.com/downloading-and-installing-node-js-and-npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
3. Install the Tailwind CSS CLI: [https://tailwindcss.com/docs/installation/tailwind-cli](https://tailwindcss.com/docs/installation/tailwind-cli)

6. Create a `input.css` file in the root of your project with the following content:
4. Create a `input.css` file in the root of your project with the following content:

```css
@tailwind base;
@tailwind components;
@tailwind utilities;
@import "tailwindcss";
```

7. Create a link to the `tailwind.css` file using manganis somewhere in your rust code:
5. Create a link to the `tailwind.css` file using manganis somewhere in your rust code:

```rust
{{#include src/doc_examples/tailwind.rs}}
```

### Bonus Steps

1. Install the tailwind css vs code extension
1. Install the Tailwind CSS VSCode extension
2. Go to the settings for the extension and find the experimental regex support section. Edit the setting.json file to look like this:

```json
Expand All @@ -69,15 +41,15 @@ module.exports = {

## Development

- Run the following command in the root of the project to start the tailwind css compiler:
- Run the following command in the root of the project to start the Tailwind CSS compiler:

```bash
npx tailwindcss -i ./input.css -o ./assets/tailwind.css --watch
npx @tailwindcss/cli -i ./input.css -o ./assets/tailwind.css --watch
```

### Web

- Run the following command in the root of the project to start the dioxus dev server:
- Run the following command in the root of the project to start the Dioxus dev server:

```bash
dx serve
Expand All @@ -87,7 +59,7 @@ dx serve

### Desktop

- Launch the dioxus desktop app:
- Launch the Dioxus desktop app:

```bash
dx serve --platform desktop
Expand Down