Git Product home page Git Product logo

qss's Introduction

QSS

A Simple Query Syntax for CSS Element Queries

The goal of QSS is to define a simple syntax for specifying element queries by adding a new ending part between a CSS selector list and the block of rules that help define the breakpoints when those rules are to apply.

Normally in CSS you have something like this:

selectorList { block }

We are going to add a new part for our query between the selector list and the block where we will store instructions for when the rule should apply.

selectorList <query> { block }

Because this exists as a new part between the selector list and the block of rules, if you have a list of selectors like h1, h2, h3, h4, h5, h6 {} you only need to add the query once after the selector list is complete, like h1, h2, h3, h4, h5, h6 <query> {} rather than h1 <query>, h2 <query>, h3 <query>, ….

This document describes two different formats for expressing element queries for individual CSS rules, one using an if-based structure, and another that uses the @ symbol to declare when it should apply.

Phrase Formats

1) if <condition> <comparator> <breakpoint>

  • operator: if
  • condition: width | height | characters | children | xscroll | yscroll
  • comparator: < | below | under | <= | max | == | equals | >= | min | > | above | over
  • breakpoint: <number>

Examples

div if width above 500 {}
input if characters under 1 {}

2) @ <comparator> <breakpoint> <condition>

  • operator: @
  • comparator: < | below | under | <= | max | == | equals | >= | min | > | above | over
  • breakpoint: <number>
  • condition: width | height | characters | children | xscroll | yscroll

Examples

div @ above 500 width {}
input @ under 1 characters {}

In both phrase formats the whitespace between tokens is optional, this means that if you prefer to think about these as @above or @min you can express them that way. The following should all equivalent:

div if width >= 500 {}
div if width >=500 {}
div if width min 500 {}
div @min 500 width {}
div@min500width{}
div @ >=500 width {}

How it works

The queries parsed by QSS would be split into the following pieces:

  • selector list
  • rule block (or stylesheet?)
  • comparator
  • condition
  • breakpoint

And these could also be used to construct Element Queries for other syntaxes like:

Essentially QSS acts as a syntax to abstract away writing these: Useful Tests for JS-powered Styling

Plugin Usage

This repository contains a working proof of concept of a plugin to parse and read QSS syntax. In order to use this plugin you just need to include QSS on the page where you want it to display:

<script src=qss.js></script>

Then you're able to add queries written in QSS syntax to your site using one of the following methods: a <style> tag, a <link> tag with type=text/qss set, or a <script> tag with a type of text/qss either inline or linked externally using a src="" attribute:

<style type="text/qss"></style>
<link type="text/qss" href=stylesheet.qss rel=stylesheet>
<script type="text/qss"></script>
<script type="text/qss" src=stylesheet.qss></script>

Links

qss's People

Contributors

tomhodgins avatar

Watchers

 avatar  avatar

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.