Microsass is a script that can convert the basic structures of SCSS into CSS directly in the browser.
Microsass can process the staggered selectors of SCSS, and supports the declaration and use of basic variables, as well as the basic arithmetic processing of variables.
It also interprets the properties to add the -webkit, -moz-, -o and -ms required.
Microsass supports sass staggered selectors, the use of & (self selector), @media screen, @keyframes and @font-face.
Microsass allows to create variables using $size1: 300px
; and basic arithmetic processes (addition, subtraction, multiplication and division)
.item {
width: $size1 + $size2;
}
<head>
<title>Microsass</title>
<link sass="./main.scss" />
</head>
<body>
<script src="./microsass.min.js"></script>
</body>
For multiple load you can separate using commas
<link
sass="
./main.scss,
.style.scss
"
/>
Load by javaScript
<script src="./microsass.min.js"></script>
<script>
microsass.import(["./main.scss", "./style.scss"]).then(() => {
console.log("ready");
});
</script>
Convert micro sass string to css minify string
var scss = `
$w1: 400px;
$w2: 200px;
#app {
background: orange;
.item{
width: $w1 + $w2;
p {
color: white;
}
}
}
`;
var css = microsass.convert(scss);
Convert micro sass string to css with format, html format and colors
var scss = `
$w1: 400px;
$w2: 200px;
#app {
background: orange;
.item{
width: $w1 + $w2;
p {
color: white;
}
}
}
`;
var css = microsass.convert(scss, {
format: true, // default is false
html: true, // default is false, format is auto-set true when html is true
color: true // default is true, only works when html is true
});
npm install microsass -save
const microsass = require("microsass");
var css = microsass.convert(scss, {
format: true, // default is false
html: true, // default is false, format is auto-set true when html is true
color: true // default is true, only works when html is true
});
An abbreviation has been created for the media screen
Use:
@if x <= 400px {
.item {
width: 300px;
}
}
Compiled output:
@media screen and (max-width: 400px) {
.item {
width: 300px;
}
}
Cases:
@if x >= xx ----> @media screen and (min-width xx)
@if x <= xx ----> @media screen and (max-width xx)
@if y >= xx ----> @media screen and (min-height xx)
@if y <= xx ----> @media screen and (max-height xx)