How to add custom CSS files for Rails

Viewed 271

I'm using Rails 7 with Tailwind and ran rails new myapp --css tailwind which created app/assets/stylesheets/application.tailwind.css

How do you add a custom CSS file so not all our CSS is in this one file? I tried adding this file but don't know how to link it

app/assets/stylesheets/header.css

#header {
    @apply p-2;
}
1 Answers

Create a new file under app/assets/stylesheets for header.css

in app/assets/config/manifest.js add a link for headers.css

//= link_tree ../images
//= link_tree ../builds
//= link headers.css

In app/views/layouts/application.html.erb add an entry for headers in the existing stylesheet_link_tag

<%= stylesheet_link_tag "application", "headers" "data-turbo-track": "reload" %>
Related