Colori

Come usare i colori di daisyUI?

Introduzione

daisyUI è completamente personalizzabile nei temi e nei colori, quindi invece di usare classi di utility fisse come:
  • bg-green-500
  • bg-orange-600
  • bg-blue-700
  • etc.
È suggerito usare classi di utility dei colori semantiche come:
  • bg-primary
  • bg-secondary
  • bg-accent
  • etc.
Ogni nome di un colore contiene delle variabili CSS e ogni tema di daisyUI applica i valori dei colori alle classi di utility quando viene applicato.

Benefici

I colori con nomi semantici hanno maggior senso perché quando disegniamo delle interfacce non usiamo dei colori qualsiasi. Definiamo una paletta di colori specifici con nomi come primary, secondary, etc. e usiamo solo quei colori specifici nelle nostre interfacce. Inoltre, usare colori con nomi semantici facilita l'uso dei temi. Non dovresti definire i colori per la modalità scura per ogni singolo elemento e non dovresti essere limitato solamente ai temi chiaro/scuro. Puoi avere molteplici temi disponibili e ogni tema è solamente una manciata di variabili CSS.

Example of theming a div with hardcoded color values

Using hardcoded color names

This is a hardcoded dark text on a light background, it needs double the amount of class names to support dark mode.
<div class="bg-zinc-100">
  <div class="bg-zinc-50 border-zinc-200 text-zinc-800">
    This is a hardcoded dark text on a light background,
    it needs double the amount of class names to support dark mode.
  </div>
</div>
  • 🪦 Fixed color names, hardcoded based on the value
  • 🚫 No automatic dark mode
  • 😵‍💫 You have to add dark-mode colors for every element
  • 💸 high maintenance cost
  • 🐢 slow development
  • 😩 hard to change a theme
  • ⛓️‍💥 high chance of inconsistency
  • 😰 You are limited to 2 themes only: light and dark

Using semantic color names

This is dark text on a light background, which switches to light text on a dark background in dark mode.
<div class="bg-base-200">
  <div class="bg-base-100 border-base-300 text-base-content">
    This is dark text on a light background,
    which switches to light text on a dark background in dark mode.
  </div>
</div>
  • 🎯 Semantic names, based on the purpose of the color
  • ✨ Automatic dark mode
  • 🌓 No need to add any dark-mode class names
  • 🤑 Zero maintenance cost to add a theme
  • 🚀 Fast development
  • ⚡️ Easy to change themes
  • 📘 All colors are consistent based on the design system
  • ♾️ Unlimited themes, easy to switch

Lista di tutti i nomi dei colori di daisyUI

Puoi usare questi nomi dei colori nel tuo tema o nelle classi di utility.
Color nameCSS variableWhere to use
primary--color-primaryPrimary brand color, The main color of your brand
primary-content--color-primary-contentForeground content color to use onprimarycolor

secondary--color-secondarySecondary brand color, The optional, secondary color of your brand
secondary-content--color-secondary-contentForeground content color to use onsecondarycolor

accent--color-accentAccent brand color, The optional, accent color of your brand
accent-content--color-accent-contentForeground content color to use onaccentcolor

neutral--color-neutralNeutral dark color, For not-saturated parts of UI
neutral-content--color-neutral-contentForeground content color to use on neutral color

base-100--color-base-100Base surface color of page, used for blank backgrounds
base-200--color-base-200Base color, darker shade, to create elevations
base-300--color-base-300Base color, even more darker shade, to create elevations
base-content--color-base-contentForeground content color to use onbasecolor

info--color-infoInfo color, For informative/helpful messages
info-content--color-info-contentForeground content color to use oninfocolor
success--color-successSuccess color, For success/safe messages
success-content--color-success-contentForeground content color to use onsuccesscolor
warning--color-warningWarning color, For warning/caution messages
warning-content--color-warning-contentForeground content color to use onwarningcolor
error--color-errorError color, For error/danger/destructive messages
error-content--color-error-contentForeground content color to use onerrorcolor

Come usare

Alcuni componenti di daisyUI mettono a disposizione delle classi modificatrici che applicheranno un colore. Per esempio:
<button class="btn btn-primary">Button</button>
Oppure:
<input type="checkbox" class="checkbox checkbox-secondary" />

These components automatically set the correct background color, text color, border color, etc as needed so you don't need to set those colors manually. For examplebtn-primarysetsprimarycolor for background and border, and setsprimary-contentcolor for the text automatically as default. You can customize them using utility classes if you want to change the color.

Puoi inoltre usare i nomi dei colori nelle classi di utility proprio come con i nomi dei colori originali di Tailwind. Queste sono le classi di utility che possono essere usate con un nome di un colore:
CSS Class
bg-{COLOR_NAME}Also available on CDN/colors/properties.css
text-{COLOR_NAME}Also available on CDN/colors/properties.css
border-{COLOR_NAME}Also available on CDN/colors/properties.css
from-{COLOR_NAME}Also available on CDN/colors/properties-extended.css
via-{COLOR_NAME}Also available on CDN/colors/properties-extended.css
to-{COLOR_NAME}Also available on CDN/colors/properties-extended.css
ring-{COLOR_NAME}Also available on CDN/colors/properties-extended.css
fill-{COLOR_NAME}Also available on CDN/colors/properties-extended.css
stroke-{COLOR_NAME}Also available on CDN/colors/properties-extended.css
shadow-{COLOR_NAME}Also available on CDN/colors/properties-extended.css
outline-{COLOR_NAME}Also available on CDN/colors/properties-extended.css
divide-{COLOR_NAME}
accent-{COLOR_NAME}
caret-{COLOR_NAME}
decoration-{COLOR_NAME}
placeholder-{COLOR_NAME}
ring-offset-{COLOR_NAME}

So you can usebg-primary,border-secondary, etc. Read more aboutdaisyUI color utility classes.

Color opacity and muted colors

base-contentis the text color of the page by default. It's a dark color on light themes and it's a light color on dark themes.

nord theme
text-base-content
dracula theme
text-base-content

Sometimes we need a muted text. something with less contrast. The best way to do this is using Tailwind CSS color opacity modifier by adding a/50(or any other value) to the end of color name. Liketext-base-content/50

nord theme
text-base-content
text-base-content/70
text-base-content/50
text-base-content/30
dracula theme
text-base-content
text-base-content/70
text-base-content/50
text-base-content/30

The advantage of using opacity is that it gives a constant result on all themes, for all colors.
You can use it with any opacity value, you can use it for any color. For example primary-content:

nord theme
text-primary-content
text-primary-content/50
dracula theme
text-primary-content
text-primary-content/50
daisyUI store

NEXUS
Official daisyUI Dashboard Template

Available on daisyUI store

More details