css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              # 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?

            
          
!
            
              :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);
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console