- 入门
- 核心概念
- 定制
- Base Styles
- 布局
- Flexbox & Grid
- Flex Basis
- Flex Direction
- Flex Wrap
- Flex
- Flex Grow
- Flex Shrink
- Order
- Grid Template Columns
- Grid Column Start / End
- Grid Template Rows
- Grid Row Start / End
- Grid Auto Flow
- Grid Auto Columns
- Grid Auto Rows
- Gap
- Justify Content
- Justify Items
- Justify Self
- Align Content
- Align Items
- Align Self
- Place Content
- Place Items
- Place Self
- 间隔
- 尺寸
- 排版
- Font Family
- Font Size
- Font Smoothing
- Font Style
- Font Weight
- Font Variant Numeric
- Letter Spacing
- Line Clamp
- Line Height
- List Style Image
- List Style Position
- List Style Type
- Text Align
- Text Color
- Text Decoration
- Text Decoration Color
- Text Decoration Style
- Text Decoration Thickness
- Text Underline Offset
- Text Transform
- Text Overflow
- Text Wrap
- Text Indent
- Vertical Align
- Whitespace
- Word Break
- Hyphens
- Content
- 背景
- 边框
- Effects
- Filters
- 表格 Tables
- Transitions & Animation
- Transforms
- Interactivity
- SVG
- Accessibility
- 其他
- Install Tailwind CSS using PostCSS
- Framework Guides
- Try Tailwind CSS using the Play CDN
- Install Tailwind CSS with Next.js
- Install Tailwind CSS with Laravel
- Install Tailwind CSS with Vite
- Install Tailwind CSS with Nuxt
- Install Tailwind CSS with Gatsby
- Install Tailwind CSS with SolidJS
- Install Tailwind CSS with SvelteKit
- Install Tailwind CSS with Angular
- Install Tailwind CSS with Ruby on Rails
- Install Tailwind CSS with Remix
- Install Tailwind CSS with Phoenix
- Install Tailwind CSS with Parcel
- Install Tailwind CSS with Symfony
- Install Tailwind CSS with Meteor
- Install Tailwind CSS with Create React App
- Install Tailwind CSS with Adonis
- Install Tailwind CSS With Ember.js
- Install Tailwind CSS with Astro
- Install Tailwind CSS with Qwik
- Install Tailwind CSS with Rspack
Install Tailwind CSS with Phoenix
Setting up Tailwind CSS in a Phoenix project.
Create your project
Start by creating a new Phoenix project if you don't have one set up already. You can follow their installation guide to get up and running.
Terminalmix phx.new myprojectcd myproject
Install the Tailwind plugin
Add the Tailwind plugin to your dependencies and run
mix.exsmix deps.get
to install it.defp deps do [ {:tailwind, "~> 0.1", runtime: Mix.env() == :dev} ] end
Configure the Tailwind plugin
In your
config.exsconfig.exs
file you can set which version of Tailwind CSS you want to use, the path to your Tailwind config, and customize your asset paths.config :tailwind, version: "3.4.4", default: [ args: ~w( --config=tailwind.config.js --input=css/app.css --output=../priv/static/assets/app.css ), cd: Path.expand("../assets", __DIR__) ]
Update your deployment script
Configure your
mix.exsassets.deploy
alias to build your CSS on deployment.defp aliases do [ setup: ["deps.get", "ecto.setup"], "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], "ecto.reset": ["ecto.drop", "ecto.setup"], test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"], "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"] ] end
Enable watcher in development
Add Tailwind to your list of watchers in your
dev.exs./config/dev.exs
file.watchers: [ # Start the esbuild watcher by calling Esbuild.install_and_run(:default, args) esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]}, tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]} ]
Install Tailwind CSS
Run the install command to download the standalone Tailwind CLI and generate a
Terminaltailwind.config.js
file in the./assets
directory.mix tailwind.install
Configure your template paths
Add the paths to all of your template files in your
tailwind.config.js./assets/tailwind.config.js
file./** @type {import('tailwindcss').Config} */ module.exports = { content: [ './js/**/*.js', '../lib/*_web.ex', '../lib/*_web/**/*.*ex', ], theme: { extend: {}, }, plugins: [], }
Add the Tailwind directives to your CSS
Add the
app.css@tailwind
directives for each of Tailwind’s layers to./assets/css/app.css
@tailwind base; @tailwind components; @tailwind utilities;
Remove the default CSS import
Remove the CSS import from
app.js./assets/js/app.js
, as Tailwind is now handling this for you.// Remove this line if you add your own CSS build pipeline (e.g postcss). import "../css/app.css"
Start your build process
Run your build process with
Terminalmix phx.server
.mix phx.server
Start using Tailwind in your project
Start using Tailwind’s utility classes to style your content.
index.html.heex<h1 class="text-3xl font-bold underline"> Hello world! </h1>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论