Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                # SusyCSS: *Susy without Sass*

This is a near-complete implementation of 
[Susy 3](https://github.com/oddbird/susy/releases/tag/3.0.0.alpha.1), 
built entirely with CSS Variables (custom properties). 

[Check out the Demo »](https://codepen.io/mirisuzanne/pen/PboVrw?editors=0100)

(this pen is intentionally unstyled,
containing only CSS variables,
so that it can be pasted anywhere)

---

## Global Settings

These variables should be set
on the `:root` element,
so that they inherit.

- `--susy-columns: 4;`
  » [integer] 
  *available columns on the grid*
- `--susy-gutters: 0.25;`
  » [number] 
  *relative size of a gutter to a column*
- `--susy-spread: 0;`
  » [-1 | 0 | 1] 
  *number of span gutters in relation to columns*
- `--susy-container-spread: 0;`
  » [-1 | 0 | 1] 
  *number of container gutters in relation to columns*
- `--susy-debug-color: hsla(0, 0%, 0%, 0.125);`
  » [color] 
  *used to show columns when debugging*

For fully-static grids, set `--susy-static-grid`.
For static-gutters on an otherwise fluid grid,
set `--susy-static-gutters`.
If either value is true,
make sure you set the desired column-width.

- `--susy-static-grid: 0;`
  » [boolean] 
  *0 for fluid (%) output, 1 for static (based on column-width)*
- `--susy-static-gutters: var(--susy-static-grid);`
  » [boolean] 
  *0 for fluid (%) gutters, 1 for static (based on column-width)*
- `--susy-column-width: 5em;`
  » [length] 
  *width of one column, when using static output*


## Returned Values

These variables represent Susy's output —
like the return value from a Sass function.
They can be applied to any property,
or used inside `calc()` 
for more complex math.
Don't set these, just use them!

- `--span-width` (`--fluid-span` / `--static-span`)
  » *default, static, or fluid width for current span*
- `--gutter-width` (`--fluid-gutters` / `--static-gutters`)
  » *default, static or fluid width for current gutters*
- `--container`
  » *static width of the current columns context*


## "Mixins"

These variables work like mixins,
automatically applying returned values
to specific properties.

- `--span: initial;`
  » [integer] 
  *used to calculate the local value of `span-width`,
  and automatically applied to the `width` property.*
- `--gutters-inside: 0;`
  » [number]
  *any number of gutter-widths to apply as left/right padding*
- `--gutters-left: 0;`
  » [number]
  *any number of gutter-widths to apply as left margin*
- `--gutters-right: 0;`
  » [number]
  *any number of gutter-widths to apply as right margin*


## Debug Values

These values need to be used together,
applied to the `background` and `background-size`
properties respectively.

- `--debug-image` / `--debug-image-split`
  » *apply to `background` or `background-image` property
    to generate a gradient representing one column/gutter pair —
    use `-split` if you want half a column on each side.*
- `--debug-image-size`
  » *apply to `background-size` property
    in order to scale the background-gradient down,
    so it repeats properly across the grid.*

As always, 
the background grid gradient for debugging 
doesn't handle sub-pixel rounding. 
That's nothing new.
Maybe we could build an inline-svg background
using custom properties as well?
Something to try!

---

## Advantages

1. SusyCSS understands the DOM structure! *Settings actually inherit*!
2. No Sass required!


## Limitations

1. CSS has no necessary control structures, 
   so the syntax & settings are bulkier. 
2. SusyCSS doesn't support asymmetrical grids.
3. Within the context of a single selector,
   each variable can only have a single value.
   There is no way to pass different arguments.
4. Why build this much flexibility into a single code base?


## ToDo:

1. Can we make an inline-svg grid image?

              
            
!

CSS

              
                :root {
  /* "--susy-" variables establish the grid */
  /* settings will inherit... */
  --susy-columns: 4;
  --susy-gutters: 0.25;
  --susy-spread: 0;
  --susy-container-spread: 0;
  --susy-debug-color: hsla(0, 0%, 0%, 0.125);
  
  /* for static grids only */
  --susy-static-grid: 0; /* boolean */
  --susy-static-gutters: var(--susy-static-grid); /* boolean */
  --susy-column-width: 5em;
}

* {
  /* ...but all the math has to happen on the element. */
  
  /* INTERNAL MATH */
  /* ------------- */
  
  /* container math */
  ---su-container-sum: calc( 
      var(--susy-columns) + 
      ( 
        ( var(--susy-columns) + var(--susy-container-spread) ) 
        * var(--susy-gutters) 
      )
    );

  
  /* span math */
  ---su-span-sum:  calc( 
    var(--span) + 
    (
      ( var(--span) + var(--susy-spread) ) 
      * var(--susy-gutters)
    )
  );
  
  
  /* gutter output math */
  ---su-inside-gutters: calc( 
      var(--gutter-width) * var(--gutters-inside) 
    );
  
  ---su-gutters-left: calc( 
      var(--gutter-width) * var(--gutters-left) 
    );
  
  ---su-gutters-right: calc( 
      var(--gutter-width) * var(--gutters-right) 
    );

  
  /* background grid math */
  ---su-grid-image-sum: calc( 
      1 + var(--susy-gutters) 
    );
  ---su-grid-gutter-ratio: calc( 
      var(--susy-gutters) / var(---su-grid-image-sum) * 100%
    );
  ---su-split-gutter-ratio: calc(
      var(---su-grid-gutter-ratio) / 2
    );
  
  
  /* PUBLIC FUNCTIONS */
  /* ---------------- */  
  
  /* span functions */
  --fluid-span: calc(
      var(---su-span-sum) / var(---su-container-sum) * 100%
    );
  --static-span: calc(
      var(---su-span-sum) * var(--susy-column-width)
    );

  --span-width: calc(
    var(--static-span) * var(--susy-static-grid) +
    var(--fluid-span) * (1 - var(--susy-static-grid))
  );

  
  /* container functions */
  --container-width: calc(
      var(---su-container-sum) * var(--susy-column-width)
    );
  
  
  /* gutter functions */
  --fluid-gutters: calc(
      var(--susy-gutters) / var(---su-container-sum) * 100%
    );
  --static-gutters: calc(
      var(--susy-gutters) * var(--susy-column-width)
    );
  
  --gutter-width: calc(
      var(--static-gutters) * var(--susy-static-gutters) +
      var(--fluid-gutters) * (1 - var(--susy-static-gutters))
    );
  
  
  /* debug functions */
  --debug-image: linear-gradient(to right, 
    var(--susy-debug-color, #ccc) calc(100% - var(---su-grid-gutter-ratio)), 
    transparent calc(100% - var(---su-grid-gutter-ratio)));
  --debug-image-split: linear-gradient(to right, 
    transparent  var(---su-split-gutter-ratio), 
    var(--susy-debug-color, #ccc) var(---su-split-gutter-ratio), 
    var(--susy-debug-color, #ccc) calc(100% - var(---su-split-gutter-ratio)), 
    transparent calc(100% - var(---su-split-gutter-ratio)));
  --debug-image-size: calc(
      var(---su-grid-image-sum) / var(---su-container-sum) * 100%
    );
  
  
  
  /* PUBLIC MIXINS */
  /* ------------- */  

  --span: initial; /* integer */
  --gutters-inside: 0; /* multiplier */
  --gutters-left: 0; /* multiplier */
  --gutters-right: 0; /* multiplier */

  
  /* output */
  width: var(--span-width, initial);
  padding-left: var(---su-inside-gutters, initial);
  padding-right: var(---su-inside-gutters, initial);
  margin-left: var(---su-gutters-left, initial);
  margin-right: var(---su-gutters-right, initial);
}

              
            
!

JS

              
                
              
            
!
999px

Console