frontendfacile.it

CSS moderno per contenuti dinamici: lascia decidere lo stile ai dati (senza if in JavaScript) (opens in new tab)

Discussed on DEV

Con data-attribute, typed custom properties e style queries puoi adattare icone e varianti UI in base a valori reali (pioggia leggera/forte, sole, nuvole). Quando il contenuto è dinamico (arriva da un’API, da un CMS o da un feed), spesso finiamo per mettere in JavaScript anche logiche puramente “visive”: scegliere un’icona, impostare una variante, cambiare un colore in base a una soglia. Il problema non è solo la quantità di codice: è che stai mescolando dati e presentazione, rendendo più dif...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help