• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CSSplus is a collection of CSS Reprocessor plugins that dynamically update CSS variables

CSSplus

CSSplus is a collection of CSS Reprocessor plugins that dynamically update CSS variables.

The plugins are designed to be used in tandem, though it's possible to pick and choose which plugins you want to include in each project.

Included are the following plugins:

Usage

NPM

If you are using NPM you can include all CSSplus plugins by including the entire package:

const cssplus = require('cssplus')

This will import all CSSplus plugins and make them available to be used in your own code as:

  • cssplus.aspecty
  • cssplus.cursory
  • cssplus.scrollery
  • cssplus.selectory
  • cssplus.varsity
  • cssplus.xpathy

But if you want to include the plugins individually, you can use the module/submodule syntax:

const selectory = require('cssplus/selectory')

And this means the Selectory plugin is available to be used in your code as:

selectory.load()

Global JavaScript

To include CSSplus plugins globally (outside of a bundler like Webpack or Browserify) you must include a <script> tag to each plugin you want to use. If you want to include just Selectory for example you would include just the one file like this:

<script src=cssplus/selectory.js></script>

To include all CSSplus plugins, you'll need to include links to the following files:

<script src=cssplus/aspecty.js></script>
<script src=cssplus/cursory.js></script>
<script src=cssplus/scrollery.js></script>
<script src=cssplus/selectory.js></script>
<script src=cssplus/varsity.js></script>
<script src=cssplus/xpathy.js></script>

Aspecty: an aspect ratio property

Aspecty is a CSS reprocessor that adds support for an aspect-ratio property using JS. This plugin allows you to define a desired aspect-ratio for an element, based on its rendered width on the page.

For any element with an aspect ratio defined, event listeners will be added to reprocess the styles on the following events:

  • mouseenter
  • mouseleave
  • mousedown
  • mouseup
  • focus
  • blur

By default, Aspecty will reprocess aspect ratios by watching the following events:

  • load
  • resize
  • input
  • click

To run Aspecty whenever you want, use the aspecty.load() function in JS.

The aspect ratio property can be used in CSS with the property name --aspect-ratio and a ratio, expressed as width and height as unitless numbers, separated by a slash /:

--aspect-ratio: width/height;

You can use it in CSS like this:

div {
  background: lime;
  --aspect-ratio: 16/9;
}

Aspecty will look through the document for any element matching the selector (in this case div) and create a new rule with a height value calculated based on each matching element's offsetWidth divided by the aspect ratio defined in CSS. To animate the effect of the --aspect-ratio property, which is actually applying via height, it is necessary to set a transition on the height property like this:

transition: height .2s ease-in-out;

Test available at: test/aspecty.html

Cursory: mouse/touch cursor variables

Cursory is a CSS reprocessor that makes the following JS values available as CSS variables:

  • cursorX
  • cursorY
  • innerWidth
  • innerHeight
  • clicked

These can be used as CSS variables with the following names:

  • --cursorX
  • --cursorY
  • --innerWidth
  • --innerHeight
  • --clicked

These variables are updated at the following events:

  • mousemove
  • touchmove

In addition, the --clicked variable is changed from 0 to 1 between the mousedown and touchstart events and the corresponding mouseup or touchend events. This allows you to use the var(--clicked) ratio as a 1 or 0 in your CSS calc() functions, or as a value for opacity:; fairly easily.

To run Cursory whenever you want, use the cursory.load() function in JS.

To make an element like div follow the cursor position when using cursory, use CSS with variables like this:

div {
  width: 10px;
  height: 10px;
  position: fixed;
  background: black;
  top: calc(var(--cursorY) * 1px);
  left: calc(var(--cursorX) * 1px);
}

Test available at: test/cursory.html

Scrollery: scroll position variables

Scrollery is a CSS reprocessor that makes the following JS values available as CSS variables for any element you tell the plugin to watch:

  • scrollWidth
  • scrollHeight
  • scrollLeft
  • scrollTop

To have scrollery watch an element, you need to give that element a unique identifier, as well as add the data-scrollery attribute. The plugin will use either the value of the data-scrollery attribute, or else the value of the id (if defined) for an element.

By default, Scrollery will watch 0 elements. If you add a data-scrollery attribute to either the <html> or <body> element it will attach an event listener for the scroll event on the window, otherwise if you add the data-scrollery attribute to other elements it will add a scroll listener to that element.

To run Scrollery whenever you want, use the scrollery.load() function in JS.

<div id=example data-scrollery></div>

And the following example are both equivalent, and resolve to a name of example:

<div data-scrollery=example></div>

Once the plugin is aware of an element to watch, and the unique name of that element, it will make the above values available in the following format: --name-value, for example:

  • --example-scrollWidth
  • --example-scrollHeight
  • --example-scrollTop
  • --example-scrollLeft

Test available at: test/scrollery.html

Selectory: a selector resolver

Selectory is a CSS reprocessor that resolves selectors using JS. This plugin will read CSS selectors that end with a [test] attribute and use JavaScript to determine whether or not to apply that style to elements matching the other part of that selector. For example, the JS test 1 == 1 will always resolve to true, so a selector written for div[test="1 == 1"] {} will always apply to each div element.

By default, Selectory will reprocess selectors by watching the following events:

  • load
  • resize
  • input
  • click

To run Selectory whenever you want, use the selectory.load() function in JS.

Other things you can do with Selectory include:

Apply a rule to a div when it is wider than 300px:

div[test="this.offsetWidth > 300"] {
  background: orange;
}

Apply a rule to an input when its value="" attribute is greater than 30:

input[test="this.value > 30"] {
  background: lime;
}

Apply a rule to an input when it has a value="" attribute zero characters long:

input[test="this.value.length == 0"] {
  background: purple;
}

Apply a rule to an input when its value="" attribute is more than 5 characters long:

input[test="5 < this.value.length"] {
  background: turquoise;
}

Apply a rule to an h3 element when it contains at least one span element:

h3[test="(this.querySelector('span'))"] {
  color: red;
}

It is limited what selectors you can use with Selectory, things like :hover and pseudo-classes tend not to work as well. As well the parsing only allows for 1 test per selector, and complex selectors may not work as intended. Using selector[test=""] {} with a simple selector is best.

Test available at: test/selectory.html

Varsity: scoped variables

Varsity is a CSS reprocessor that makes the following JS values available as CSS variables for any element you tell the plugin to watch:

  • offsetWidth
  • offsetHeight
  • offsetLeft
  • offsetTop
  • aspect-ratio
  • characters
  • children
  • value

By default, Varsity will reprocess selectors by watching the following events:

  • load
  • resize
  • input
  • click

To run Varsity whenever you want, use the varsity.load() function in JS.

To have varsity watch an element, you need to give that element a unique identifier, as well as add the data-varsity attribute. The plugin will use either the value of the data-varsity attribute, or else the value of the id (if defined) for an element.

<div id=example data-varsity></div>

And the following example are both equivalent, and resolve to a name of example:

<div data-varsity=example></div>

Once the plugin is aware of an element to watch, and the unique name of that element, it will make the above values available in the following format: --name-value, for example:

  • --example-offsetWidth
  • --example-offsetHeight
  • --example-offsetLeft
  • --example-offsetTop
  • --example-aspect-ratio
  • --example-characters
  • --example-children
  • --example-value

Test available at: test/varsity.html

XPathy: XPath selectors in CSS

XPathy is a CSS reprocessor that resolves selectors using XPath. This plugin will read CSS selectors that end with a [xpath] attribute and use JavaScript and XPath to determine whether or not to apply that style to elements matching the other part of that selector. For example, the XPath selector //div will always resolve to div, so a selector written for div [xpath="//div"] {} will always apply to each div div {} element.

By default, XPathy will reprocess selectors by watching the following events:

  • load
  • resize
  • input
  • click

To run XPathy whenever you want, use the xpathy.load() function in JS.

Other things you can do with XPathy include:

Select all span tags with the XPath //span:

[xpath="//span"] {
  color: violet;
}

Select all elements with a class name of demo-class with the XPath //*[@class='demo-class']:

[xpath="//*[@class='demo-class']"] {
  color: lime;
}

Select an element with a text content of 'Demo Content' with the XPath //*[text()='Demo Content']:

[xpath="//*[text()='Demo Content']"] {
  color: violet;
}

Select the parent element of another element with the XPath /..:

[xpath="//*[@class='child']/.."] {
  border: 1px solid lime;
}

Compare attribute values as numbers with operators like > and &lt;:

[xpath="//*[@data-price > 3]"] {
  color: violet;
}

Select elements based on the number of children they contain with an XPath like //ul[li[4]]:

[xpath="//ul[li[4]]"] {
  color: lime;
}

Test available at: test/xpathy.html

Browser support

These plugins are written in ES6, and intended to be used in modern browsers (Chrome, Safari, Firefox, Edge) without transpilation. Many of these plugins make use of CSS Custom Properties (CSS variables) for functionality, so any browser that doesn't support these features will have trouble with.

As far as I am aware, the only browser that supports CSS Custom Properties but not the ES6 features used (where transpiling to ES5 might improve support) is for Mobile Safari (iOS) support.

Currently all of these plugins are under active development and things are shifting around quite a bit so browser support may change with each release.

Demos

For 20+ CSSplus demos, check out the CSSPlus demos collection on Codepen.

More Repositories

1

element-queries-spec

A spec for a Container-Style Element Query Syntax
HTML
368
star
2

dragon

dragon.js is a bookmarklet that lets you drag any element on a website using a mouse or touchscreen. The goal is to speed up in-browser design critiques and brainstorming new layout ideas.
CSS
144
star
3

preset

A simple CSS preset for 2020
CSS
144
star
4

reprocss

A flexible <style>-tag based CSS reprocessor
HTML
119
star
5

quark

Quark.js is a microscopic atomic CSS polyfill in JS just 140 bytes
HTML
97
star
6

liveeditor

A simple live HTML, CSS, and JavaScript scratchpad in your browser
HTML
88
star
7

qss

QSS ➸ a simple query syntax for CSS element queries
HTML
85
star
8

computed-variables

Easy to use event-driven CSS variables
JavaScript
80
star
9

jsincss

A JS-in-CSS stylesheet loader
JavaScript
51
star
10

boilerstrap

Boilerstrap is a WordPress theme based on the Twenty Twelve theme from Wordpress.org that includes support for Bootstrap, FontAwesome icons, custom typography, jQuery, keyboard shortcuts, & much more…
PHP
35
star
11

deqaf

Decaffeinate CSS stylesheets client-side
JavaScript
30
star
12

tinkerpad

Tinkerpad is an HTML, CSS, and JavaScript scratchpad similar to jsFiddle. Tinkerpad is written as an offline-capable HTML5 web app and requires no external dependencies.
HTML
30
star
13

caffeinated-style-sheets

Extend .css with JavaScript the easy way!
27
star
14

css-package-manager

A Package Manager for CSS Extensions
26
star
15

extstyler

Empty Chrome extension to add custom CSS or JavaScript on top of websites, ready to drop in your user styles and scripts
JavaScript
23
star
16

qaffeine

Decaffeinate your JS-powered CSS stylesheets
JavaScript
22
star
17

cheq

A command-line checklist app
JavaScript
17
star
18

wordpresto

Download, configure, and install Wordpress with one easy script
Shell
15
star
19

varius

Exposing properties of HTML elements as CSS variables
HTML
12
star
20

memopad

Memo Pad is a simple memo pad that saves your notes to localStorage, as well as allows you to share notes via URL
HTML
12
star
21

slinky

Add JavaScript tests to <link> tags to toggle stylesheets
HTML
11
star
22

js-in-css

A Pattern for simple Event-Driven Virtual Stylesheets: 100% CSS plus the expressive power of JavaScript
HTML
11
star
23

fartcss

Functional And Responsive Template is a utility class framework that uses element queries
HTML
10
star
24

parse-css

A standards-based CSS parser - forked from tabatkins/parse-css
JavaScript
9
star
25

theremin

Theremin app built using JavaScript
HTML
9
star
26

responsive.style

A Fresh Approach to Extending CSS
HTML
9
star
27

speedtest

SpeedTest is an HTML5 app that lets you test websites at a variety of resolutions very quickly. It also works on mobile, which allows you to test websites at a variety of widths on a phone or tablet where you can't normally change the width of the browser.
HTML
8
star
28

aspect-ratio-spec

A spec for an aspect-ratio property in CSS
HTML
8
star
29

cssomtools

The 'jQuery-for-the-CSSOM', a library for working with CSS stylesheets and rules in the browser
JavaScript
8
star
30

js1k-arecibo

The Arecibo Message - for JS1K 2017
HTML
7
star
31

jsts-engine

Interpolate JavaScript Template Strings
JavaScript
6
star
32

process-css-demo

A simple CSS preprocessor to demonstrate supporting custom at-rules, selectors, properties, functions, and units
JavaScript
6
star
33

basic-website-starter

A basic HTML/CSS/JS website with a simple toolchain: none
HTML
6
star
34

css-tests

Examples of CSS syntax for testing purposes
CSS
6
star
35

qaffeine-demo

A demo site of qaffeine
CSS
5
star
36

stringify-css-stylesheet

Convert a CSSStyleSheet object to a string of text
HTML
5
star
37

eqcss-compiler

A compiler to turn EQCSS syntax into equivalent (vanilla) JavaScript
JavaScript
5
star
38

5keleton

This is a blank HTML5 template with Bootstrap, jQuery, and FontAwesome already integrated. Includes meta tags for OpenGraph, iOS browsing, icons (including favicon), Windows Live Tile, and the usual keywords and description. Includes .htaccess and robots.txt as well. This is ready for you to clone and kickstart your next HTML project!
ApacheConf
5
star
39

template-factory

The Template Factory is a small website template written simply in PHP, HTML, CSS and JavaScript. Powered by EQCSS for element queries, plus lightweight plugins for tooltips, modals, notifications, and more!
CSS
5
star
40

custom-css

Examples of custom CSS
CSS
4
star
41

sbv

Read Youtube .SBV caption files and convert to JSON, text, or HTML
JavaScript
4
star
42

tweetcruncher.com

Tweet Cruncher
HTML
4
star
43

sourceror

Sourceror lets you view the source of any web page using a PHP proxy.
HTML
4
star
44

unicons

Unicons.css is a CSS file to make adding unicode characters to HTML in a semantic and easy to use way. Because Unicons.css is so lightweight you can include just one file to supplement or replace other icon font solutions on your site like FontAwesome
HTML
4
star
45

cascading-js-variables

Cascading JS Variables with a similar syntax and usage to CSS Variables, implemented in JavaScript
HTML
4
star
46

anesthetic

Nesting CSS rules inside custom properties
JavaScript
3
star
47

repl

A Web REPL for sketching out ideas
HTML
3
star
48

jsincss-has-selector

A :has() selector plugin for jsincss
JavaScript
3
star
49

jsincss-element-query

An element query plugin for jsincss
JavaScript
3
star
50

csson

Using a strict subset of CSS syntax as a superset of JSON
JavaScript
3
star
51

querious

A pure-JavaScript element query demonstration using data attributes for syntax, and applied via classes
HTML
3
star
52

bil

Basic Instruction Language
HTML
3
star
53

alijn

Alijn is a script that puts some JavaScript smarts behind your responsive CSS styles. Calculate the CSS values for tricky layout functions like vertical centering or hortizontal centering in realtime.
JavaScript
3
star
54

espath

Query deeply nested JavaScript objects with XPath
HTML
2
star
55

mathpad

Magic Mathpad: a live JavaScript calculator
HTML
2
star
56

intimateoccasions.ca

Celebrating Life's Special Moments
HTML
2
star
57

htmlforever

HTML templating helper functions written in a Continuation-Passing Style for JavaScript, Python, and Ruby
Python
2
star
58

style-container

A way to re-use CSS for scoped styles and container queries in HTML
JavaScript
2
star
59

apophany

a pattern matcher
JavaScript
2
star
60

deno-test

Begin app
TypeScript
2
star
61

deck

Deck of playing cards in HTML, CSS, and JavaScript
HTML
2
star
62

piano

HTML5 synth app for iPad
HTML
2
star
63

respec

respec allows CSS authors to assign the specificity of a rule separately from the specificity of the selector
HTML
2
star
64

sugarfree

JavaScript
2
star
65

css-overlay-snippet

A live CSS debugging stylesheet you can copy/paste into the browser's JS console
HTML
2
star
66

element-match-media

Parse media queries from the context of an element. Like window.matchMedia() but for HTML elements.
HTML
2
star
67

browserstack-app

A simple electron app for browserstack.com
JavaScript
2
star
68

loqui

Style your console.log() messages with ease
JavaScript
1
star
69

learncss

Docs for ##learncss on freenode
1
star
70

jsincss-overflow

An overflow-detecting plugin for jsincss
JavaScript
1
star
71

jsincss-elder-selector

An elder selector plugin for jsincss
JavaScript
1
star
72

jsincss-regex-match

A regex matching plugin for jsincss
JavaScript
1
star
73

domtools

HTML
1
star
74

cyfer

Cyfer - A Chrome Extension that skins gli.ph conversations
CSS
1
star
75

mixin-macros

String combinators designed to help the creation of jsincss plugins
JavaScript
1
star
76

jsincss-xpath-selector

A jsincss plugin that lets you select elements to style using XPath selectors
JavaScript
1
star
77

jsincss-element-units

An element unit plugin for jsincss
JavaScript
1
star
78

synth

Just a simple WebAudio synth. No reason. What could go wrong…
JavaScript
1
star
79

jsincss-parent-selector

A parent selector plugin for jsincss
JavaScript
1
star
80

queryxpath

Simple queryXPath() and queryXPathAll() functions for JavaScript
HTML
1
star
81

onebuttoncdn

OneButton CDN, the easiest tool for updating Bootstrap 3.0, FontAwesome, and jQuery on your own server
PHP
1
star
82

loadjs

LoadJS lets you share JavaScript on Twitter by encoding it as a URL to share
HTML
1
star
83

freshstart

Static HTML site built using HTML5, CSS, and JavaScript. No frameworks, no bootstrap, no jQuery.
HTML
1
star
84

jsincss-string-match

A string matching plugin for jsincss
JavaScript
1
star
85

domforever

DOM templating helper functions written in a Continuation-Passing Style
JavaScript
1
star
86

bengalcat.party

It's a bengal cat party!
HTML
1
star
87

hade

HTTPArchive DOM Explorer CLI tool
JavaScript
1
star
88

tomhodgins.com

Website for Tom Hodgins
1
star
89

symbolix

Symbolic expression parsing for JavaScript
HTML
1
star
90

process-css

A CSS processor with a simple plugin design that can process CSS server-side and client-side into CSS, JS, and other file output
JavaScript
1
star
91

mini-container-queries

A <200 byte container query plugin
HTML
1
star
92

parse-css-stylesheet

Parse a string of text as a CSS stylesheet with JavaScript in the browser environment
HTML
1
star