hectorperez

hectorperez

Hi,

I have a phoenix 1.6.6 app and tailwind 3.6.18 and tailwind css preflight is loading some base styles Preflight - Base styles - Tailwind CSS

The problem is that my custom css code in app.css is not replacing preflight’s in development. But it works on staging & production. I think my custom css is somehow being loaded before preflight and it should be afterwards — but not sure if this is the problem.

app.css

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

<my custom css code>

I think preflight is loaded after @import "tailwindcss/base" so it should be ok. But it isn’t working so I guess I’m missing something. Therefore, how could I make sure my custom css is loaded after preflight?

Or any idea what the problem could be? Thanks!

By the way, I know I can disable tailwind’s preflight — and my custom css works if I do — but I would like to keep it and have custom css to replace a few styles from preflight.

postcss.config.js

module.exports = {
  plugins: {
    "postcss-import": {},
    tailwindcss: {},
    autoprefixer: {},
  }
}

tailwind.config.js

module.exports = {
  mode: 'jit',
  purge: [
    './js/**/*.js',
    '../lib/*_web/**/*.*ex'
  ],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

Thanks!

Showing Posts 1 to 10

derek-zhou

derek-zhou

I dunno, but my setup works:

@tailwind base;
@tailwind components;
@tailwind utilities;

<my custom css code>

My postcss.config.js

module.exports = {
    plugins: [
        require('tailwindcss/nesting'),
        require('tailwindcss'),
        require('autoprefixer'),
    ],  
};
thiagomajesk

thiagomajesk

I think you have to use the @layer base directive for that… Per the documentation:

If you want to add your own default base styles for specific HTML elements, use the @layer directive to add those styles to Tailwind’s base layer.

I think this is also cross-referenced from the docs on the page you posted.
BTW, you can also look at the typography-plugin source code since they do basically the same thing - or open a discussion on the Tailwind repo if that’s the case.

hectorperez

hectorperez OP

Thank you @derek-zhou and @thiagomajesk for your comments.
I still couldn’t make it work tweaking postcss.config.js or using @layer base.

It seems most custom css is replacing preflight’s, except background-color: transparent; from buttons/submits.
I see on preflight button reset in v3 inconsistent with v2 · Issue #6602 · tailwindlabs/tailwindcss · GitHub that more people had problems with that.

However, in staging & production does work for me but not in development.
Any idea? Thanks!!

odix67

odix67

by looking in the tailwindcss documentation, you are able to extend or disable preflight https://tailwindcss.com/docs/preflight

hectorperez

hectorperez OP

Thanks @odix67 for your comment.

If I disable preflight, it works. However, I’d like to keep it as I use some components from https://tailwindui.com and they rely on the styles of preflight.

hectorperez

hectorperez OP

By the way, extending preflight doesn’t seem to work either:

app.css

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

<other imports>

@layer base {
  button,.button,input[type='button'],input[type='reset'],input[type='submit'] {
    @apply bg-blue-600;
  }
}

<other custom css>

The background-color of my buttons is still transparent as defined by preflight.

Did I miss anything when extending preflight?
Thanks!

derek-zhou

derek-zhou

Why you insist on:

While all tailwind examples I have seen use the following:

@tailwind base;
@tailwind components;
@tailwind utilities;
thiagomajesk

thiagomajesk

@derek-zhou It’s actually a perfectly valid way of using it you are importing multiple files, you can read here why it’s necessary: Using with Preprocessors - Tailwind CSS. I also do this and it shouldn’t be the cause of the problem.

@hectorperez If I may, since this is not an elixir/ phoenix problem I think you should open an issue/ discussion in the tailwind repo, perhaps it’s something that’s already been tracked or discussed. IMHO, your chances of getting better support will increase because there are certainly people more focused on this particular subject over there.

hectorperez

hectorperez OP

Thanks @thiagomajesk.

I asked here because it works in staging & production but not in development so maybe someone here know why.
But I’ll try to ask there too, thanks.

thiagomajesk

thiagomajesk

Can you post your CSS build setup for those environments?

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews