Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to use CSS Variables with Ruby on Rails Discussion

I asked a question on discord and thought it might be good for it to be here for future reference.
https://discord.com/channels/874684608686477352/874684609164640358/958015390347329658

Question:
I was wondering of a way to dynamically change which class you are calling. ie:
'<%= "text-#{color} bg-#{color}" %>' << this code is not recommended since tailwind needs the full class name to build.

Answer(chris):
you can supply a custom color to Tailwind in the config
module.exports = {
colors: {
'primary': 'var(--primary-color)',
same thing as a regular color there

Reply

Thank you for visiting here.

Reply

Very informative, thank you Chris and Willard!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 77,200+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.