

Enjoy writing CSS in your JS? Try writing JS in your CSS! ?
source link: https://www.tuicool.com/articles/7ZzIJrv
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

CJSS
A CSS based web framework
Also, don’t use this project, especially not for anything serious. This is a joke and thught experiment. I won’t help you work through bugs.
To install CJSS, add the JavaScript to your website.
Using CJSS
First off, everything happens in your CSS file. You can layer this into your websites as you see fit. You can use this to layer on just a little bit more functionality in your CSS here and there or construct an entire page. It’s up to you!
HTML
To add markup to an element, select it in your CSS file, then using --html:(your markup here);
add your HTML. This markup will appear everywhere that matches your CSS selector and overwrite whatever was there before.
h1 { --html:( This is a headline ); }
If you wish to pass content through a component, use ${yield}
.
<component>My Component</component>
component { --html:( <h2>${yield}</h2> <p>This is a component</p> ); }
This will render as:
<component> <h2>My Component</h2> <p>This is a component</p> </component>
JavaScript
You can use JavaScript to define the behavior of things right from your HTML. You want something to happen on a thing when you click it and don’t want to go into your JS file? Do it right from your CSS file. If you are selecting the script
element it will assume you are writing a global script, but everywhere else, the keyword this
will map to the selector you are in.
.item { cursor: pointer; --js:( function toggle() { this.classList.toggle('active'); } this.addEventListener('click', toggle ); ); }
Data
You can add data to your project. Probably useful for something. Do it using the --data
attribute. It should be formatted as JSON.
nav { --data:( name: ['one', 'two', 'three'], link: ['#one', '#two', '#three'], ); --html:( <a class="item" href="${data.link[0]}">${data.name[0]}</a> <a class="item" href="${data.link[1]}">${data.name[1]}</a> <a class="item" href="${data.link[2]}">${data.name[2]}</a> ); --js:(console.log(data)); }
Play with CJSS on Codepen
Recommend
-
127
Page not found · GitHub · GitHub Skip to content...
-
49
Creating UIs with CSS is rarely as straightforward as you expect. A few weeks ago I wanted to make the navigation on my site responsive, having it switch from a row of links to a hamburger slideout menu. Seems li...
-
39
I really used to like C# This was my primary language, every time I compared it to other popular languages I was happy I accidentally chose it. Python and Javascript lack static typing (assuming JS has any kin...
-
15
No need for drama. Enjoy your ice cream. Life's been pretty good since I escaped from that place in Mountain View. It means I've been relatively relaxed. Being able to set my own schedule certainly helps. If it's a beautiful d...
-
14
Feed Your RSS and Enjoy Delicious ContentOctober 1st 2021 new story7 RSS is a protocol that allows us...
-
9
-
5
Why I Don’t Enjoy Writing PHP AnymoreThis post was started from my Twitter thread, please follow me t...
-
8
Nov 21, 2022 — 12:00 CUT Boom 3D: Enjoy Immersive Audio on Your Mac [Sponsor] ...
-
10
Frontend Focus Issue 580 Easy to unsubscribe at any time. Your e-mail address is safe — here's
-
7
Try out CSS Nesting today Feb 8, 2023
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK