Skip to content
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

bug: table-zebra class not applying background color as expected #3275

Open
algowhiz opened this issue Nov 14, 2024 · 4 comments
Open

bug: table-zebra class not applying background color as expected #3275

algowhiz opened this issue Nov 14, 2024 · 4 comments

Comments

@algowhiz
Copy link

What version of daisyUI are you using?

v4.0.3

Which browsers are you seeing the problem on?

Chrome

Reproduction URL

https://play.tailwindcss.com/8cZeWJ3aSo?file=css

Describe your issue

The table-zebra class is not applying the expected background color in an alternating row pattern due to conflicts with custom color settings in the project. This affects readability as the alternating background colors do not appear as intended.

Expected Behavior: The table-zebra class should display distinct background colors on alternate rows, overriding custom colors to ensure consistent styling for better readability.

Actual Behavior: Due to custom color definitions, the background color for alternate rows is not applied as expected. Applying an !important flag to the table-zebra row colors could potentially resolve this issue.

// Apply alternating background colors to table-zebra rows

.table-zebra tbody tr:nth-child(odd) {
background-color: #f9fafb !important; //light
}

.table-zebra tbody tr:nth-child(even) {
background-color: #e5e7eb !important; //dark
}

Copy link

Thank you @algowhiz for reporting issues. It helps daisyUI a lot 💚
I'll be working on issues one by one. I will help with this one as soon as a I find a solution.
In the meantime providing more details and reproduction links would be helpful.

@euglv
Copy link

euglv commented Nov 15, 2024

https://play.tailwindcss.com/8cZeWJ3aSo?file=css

You forget

  plugins: [require('daisyui')],

in the tailwind config.
Removing !important from your custom css changes nothing in the output.

@AerisG222
Copy link

not sure if this is the same thing you are running into, but looking at styled.css in the latest daisyui (4.12.14), you can see the following:

.table-zebra tr.active,
    .table-zebra tr.active:nth-child(even),
    .table-zebra-zebra tbody tr:nth-child(even) {
    --tw-bg-opacity: 1;
    background-color: var(--fallback-b3,oklch(var(--b3)/var(--tw-bg-opacity)))
}

if you add the table-zebra-zebra class, do you get the striping you expect?

I realize this is a workaround, but I was looking into something similar in my project and came across this...

Hope this helps,
Mike

@algowhiz
Copy link
Author

You can reply with the following message to address the issue constructively:

Thank you, @AerisG222, @euglv for your input and assistance!

I appreciate the suggestions. Here’s an update and clarification:

I’ve ensured that plugins: [require('daisyui')], is included in the Tailwind config, and that does resolve the issue with daisyUI not initializing correctly.
I also tried adding the .table-zebra-zebra class as you suggested, @AerisG222. It does help apply the striping correctly. However, the .table-zebra class alone should ideally handle this without needing additional classes.
Given the complexity caused by custom colors, I’ll explore applying the custom CSS with !important as a temporary fix for my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants