DEV Community

FSCSS tutorials for FSCSS tutorials

Posted on • Edited on

How to Import FSCSS from javascript in HTML

Import FSCSS from javascript file.
In my javascript file I do something like this:

//fscss.js
//FSCSS4
async function styleWith(e){
let fscss = await import("https://cdn.jsdelivr.net/gh/Figsh/FSH@2.1.0/fshapi.js");
var e = fscss.write;
var text = (`
$rgb: %3([200,]);
$bg-color: #00F0F0;
.box{
  %2(
   Width, 
   Height[: 100px;])                                                                                
            background: $bg-color!;
Border: 4px solid rgb($rgb!1);
} 
Re(animationSettings:'3s linear infinite alternate forwards')
$(@keyframes box, .box &[animationSettings]) {
0%{
Transform: rotateX(0);
}
100%{
Transform: rotateX(360deg);
}}
`);
fscss.exec(e, text);
}
styleWith(this);
Enter fullscreen mode Exit fullscreen mode

Index.html:

<!--- index.html --->
<!DOCTYPE html>
<haed>
<title>JavaScript FSCSS</title>
</head>
<body>
<div class='box'></div>
<script src='scripts/fscss.js'></script>
</body>
Enter fullscreen mode Exit fullscreen mode

Example:

<!DOCTYPE html>
<html>
<body>
<div class='box' name='box'></div>
<script  src="https://cdpn.io/cpe/boomboom/pen.js?key=pen.js-4b571a79-5bd4-c6de-a17d-ef34f7c91e90"></script>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

Demo:

Method 2
Test code:

<div contenteditable="true"></div>
<script>
(async function(){
let i = await import('https://cdn.jsdelivr.net/gh/Figsh/FSH@2.1.0/fshapi.js');
fscss = i.write;
new i.exec((fscss), (`
body{ 
background: #eefeee;
}
$(contenteditable){
border: 4px solid #7eeff7;
caret-color: red;
}
`));
})()
</script>
Enter fullscreen mode Exit fullscreen mode

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more