-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Closed
Description
To prevent repetition both in CSS and HTML we can use a component. However, when working with static lists it may not be a good idea to have every list item as a component.
A simplified example below:
<ul>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">Home</li>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">About</li>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">Projects</li>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">Hello</li>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">World</li>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">Foo</li>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">Bar</li>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">Tail</li>
<li class="bg-red-500 hover:bg-red-700 rounded text-sm text-white">Wind</li>
<ul>For static lists like this you could split the data into an array and keep the classes as a variable. It's a bit more hassle and not always as readable.
Solution - Child selectors
Let's take the first example again:
<ul class="bg-red-500> hover:bg-red-700> rounded> text-sm> text-white>">
<li>Home</li>
<li>About</li>
<li>Projects</li>
<li>Hello</li>
<li>World</li>
<li>Foo</li>
<li>Bar</li>
<li>Tail</li>
<li>Wind</li>
<ul>- When need to change a class, you only do that in one place.
- It should only affect direct children, not grand children.
- Children classes on the li should override the child class set in the ul.
- I put
>last as class names needs to start with a letter. - Very similar to the current Tailwind syntax.
Cons
I can only come up with one con at the moment.
- It would probably double the filesize of the CSS file before purge.
cmdumar, nikdanilov, audacioustux, MSKhodadady, hahuaz and 25 more
Metadata
Metadata
Assignees
Labels
No labels