Coder Social home page Coder Social logo

zcss.js's Introduction

zcss

Minimal nested CSS preprocessor in ~30 lines of JavaScript

/* button.zcss */

:root {
  --blue: #8098d4;
}

.button {
  background: var(--blue);
  border-radius: 4px;
  font-size: 18px;

  &:hover {
    transform: scale(1.1);
  }

  &[disabled] {
    opacity: 0.5
  }

  .icon {
    margin-right: 1em;
  }
}

Compile zcss to css:

$ cat button.zcss | node zcss > button.css

Syntax

This preprocessor implements just two core features inspired by SCSS, Less, and the CSS Nesting draft spec -- implicit nesting, and the ampersand selector.

Implicit nesting

section {
  p {
    line-height: 2;
  }
}

/* section p {
 *   line-height: 2;
 * }
 */

Each property must be on its own line, separate from its selector.

Ampersand selector

section {
  &:hover {
    color: purple;
  }
}

/* section:hover {
 *  color: purple;
 * }
 */

The ampersand must appear exclusively at the beginning of the selector (similarly to the & in CSS Nesting)

zcss.js's People

Contributors

dchester avatar

Stargazers

Tomás Pollak avatar ⊣˚∆˚⊢ avatar  avatar Neos21 avatar Masahiro Miyashiro (3846masa) avatar  avatar

Watchers

 avatar James Cloos avatar

zcss.js's Issues

Bug around {}

thanks for the great library

I think the output is strange if you don't put a newline in {}.

example

The output is as follows, so could you please fix it?

NG

input

div{color: red}

output

}
}

NG

input

div{
}

output

}

OK

input

div{
  color: red
}

output

div{
  color: red
}

my environment

windows 10
Chromium: 105.0.5195.127

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.