Here’s the documentation for implementing similar state-based styling using only HTML and CSS without a CSS framework:
Introduction
This guide demonstrates how to implement state-based styling similar to what
@flexilla/uno-preset
or @flexilla/tailwind-plugin
provide, using only HTML and CSS. We will focus on managing element states like
open
, active
, visible
, etc., using the data-state
attribute for simplicity. Defining State-Based Styles
We’ll directly use attribute selectors in CSS. For example, to apply styles based on a
data-state
attribute, we can write the following: Available States
Here are the states we will use for demonstration:
-
open
-
closed
-
active
-
inactive
-
visible
-
hidden
Example 1: Open and Close States
HTML
CSS
In this example, elements with
data-state="open"
are styled with a green background, while elements with data-state="closed"
have a red background. Example 2: Active and Inactive States
HTML
CSS
Example 3: Visibility States
HTML
CSS
Here, content with
data-state="hidden"
is hidden from view using display: none
. In this case, the button with both
data-state="active open"
will be styled with a dark green background and yellow text. Example 5: Transition and Animation
For dynamic interactions like modals or tab panels, you can use CSS transitions or animations.
HTML
CSS
This modal will fade in when its
data-state
is set to open
.