DEV Community

Discussion on: if/else in CSS

Collapse
 
iamschulz profile image
Daniel Schulz

But there are already conditional statements in CSS, they're just not named if/else.

:checked { /* if */ }
:not(:checked) { /* else */ }

[data-attr="true"] { /* if */ }
[data-attr="false"] { /* elseif */ }
:not([data-attr]) { /* else */}
Enter fullscreen mode Exit fullscreen mode

As to the new synatx: I'm curious if it's going to solve componentization issues or rather introduce new side effects and specificity problems. I'll be happy to stay with the old and trusty

width: var(--s-width);
@media (min-width > 600px) {
    width: var(--l-width);
}
Enter fullscreen mode Exit fullscreen mode

for as long as new best practices haven't surfaced. I guess i'm just used to structure my styles by viewport and not by instructions.

Collapse
 
mrbns profile image
Mr. Binary Sniper

These are different things..