quantum-css
quantum-css copied to clipboard
Atomic CSS library written in SCSS.
Quantum CSS
“Everything should be made as simple as possible, but no simpler.” – Albert Einstein 1
Preface
Quantum CSS is an atomic CSS library written in SCSS.
You won’t need to write any CSS rules and media queries while using Quantum CSS. Creating highly responsive UIs becomes pleasure while extension pattern provides means of controlled customization. You can create molecules with avaialble atoms using @extend.
Here is a sample button component with rounded corners, hover and focus transition animations (which are disabled on small screens to provide better experience on touch devices):
<button class="btn btn-fb" type="button">
<!-- Content -->
</button>
.btn {
@extend .px15, .h40; // Size
@extend .bds-s, .bdw1, .bdr5; // Border style solid, border width 1px and rounded corners
@extend .trp-c, .trd200ms; // Color transitions
&-fb { @extend .bgc-fb, .c-w, .bdc-tt, .SM_bgc-dfb-hf } // Facebook
&-tw { @extend .bgc-tw, .c-w, .bdc-tt, .SM_bgc-dtw-hf } // Twitter
}
Benefits of using @extend approach:
-
Highly standardized styles. Limited amount of building blocks allows you to have more order in your design.
-
Stylesheet compilation time errors. Build fails if unknown atoms are used.
-
Easy to remember class names. Atoms naming convention was heavily inspired by Emmet, and most of the time abbreviations are first letters of words that property or value names consist of.
Contents
- Naming Conventions
- Value Aliases
- Color Values
- Unit-less Properties
-
Breakpoints
-
Pseudo-classes and Pseudo-elements
-
Grid System
- Containers
- Rows
- Columns
- Column Ordering
- Atom Index
-
Name Pattern
-
Background
background-color
background-attachment
background-clip
background-image
background-origin
background-repeat
background-sizebackground-position
background-position-x
background-position-yfill -
Border
border-color
border-top-color
border-right-color
border-bottom-color
border-left-colorborder-width
border-top-width
border-right-width
border-bottom-width
border-left-widthborder-style
border-top-style
border-right-style
border-bottom-style
border-left-styleborder-radius
border-top-right-radius
border-top-left-radius
border-bottom-right-radius
border-bottom-left-radius -
Images
object-fit -
Transforms
transform -
Flexible Box Layout
flex-direction
flex-wrap
flex-grow
flex-shrink
flex-basis
justify-content
align-items
align-content
align-self
order -
Positioning
float
clear
position
top
right
bottom
left
z-index -
Fonts
font-size
line-height
font-family
font-weight
font-style
font-variant
font-size-adjust
font-stretch
-webkit-font-smoothing
-moz-osx-font-smoothing -
Transitions
transition-property
transition-duration
transition-timing-function -
Text
letter-spacing
overflow-wrap
text-align
text-align-last
text-indent
text-decoration
text-transform
white-space
word-break
word-wrap -
Lists and Counters
list-style
list-style-position
list-style-type -
Colors
color
opacity -
Box Model
box-sizing
height
width
margin
padding
overflow
overflow-x
overflow-y
-webkit-overflow-scrolling
visibility -
Page
page-break-before
page-break-inside
page-break-after -
User Interface
cursor
resize
text-overflow
user-select -
Table
border-collapse
caption-side
empty-cells
table-layout
vertical-align -
Miscellaneous
display
- License
Naming Conventions
In Quantum CSS every class name consists of four parts in given order:
- Optional breakpoint name:
SM,MDetc. - Property abbreviation:
bdtc,wsetc. - Value abbreviation:
w,100p,360detc. - Optional pseudo-class or pseudo-element modifier:
hf,hetc.
You can configure separators between each parts of class name with following variables:
-
$breakpoint-sepdefine separator between breakpoint name and property abbreviation. -
$literal-sepand$ordinal-sepdefine separators that are inserted between property name and literal value abbreviation or ordinal one respectively. -
$pseudo-sepdefines separator between pseudo modifier from value abbreviation.
Value Aliases
Aliases for commonly used values:
p→%e→emx→exr→remd→degt→turn
These aliases are used instead of full units:
w100p→width: 100%SM_mah42→@media (min-width: 576px) { max-height: 42px }
Color Values
Names for colors are used fo increase readability. By default, Tango palette is used for every color-related atom. You can specify your own palette overriding variables in _variables.scss.
| Greyscale | Value |
|---|---|
1. White w |
#fff |
2. Grey 15% g1 |
#eeeeec |
3. Grey 30% g2 |
#d3d7cf |
4. Grey 45% g3 |
#babdb6 |
5. Grey 60% g4 |
#888a85 |
6. Grey 75% g5 |
#555753 |
7. Grey 90% g6 |
#2e3436 |
8. Black b |
#000 |
| Color | Light l |
Medium | Dark d |
|---|---|---|---|
9. Yellow y |
#fce94f |
#edd400 |
#c4a000 |
10. Orange o |
#fcaf3e |
#f57900 |
#ce5c00 |
11. Chocolate c |
#e9b96e |
#c17d11 |
#8f5902 |
12. Green g |
#8ae234 |
#73d216 |
#4e9a06 |
13. Navy n |
#729fcf |
#3465a4 |
#204a87 |
14. Purple p |
#ad7f8a |
#75507b |
#5c3566 |
15. Red r |
#ef2929 |
#cc0000 |
#a40000 |
CSS-literal colors:
cc→currentColort→transparenti→inherit
Generated atom examples:
SM_bgc-dg→background-color: #4e9a06Dark greenbdrc-w→border-right-color: whiteLG_c-b→color: black
Unit-less Properties
Some CSS properties are defined as unit-less, e.g. no unit suffix will be outputted:
lh1→line-height: 1fw400→font-weight: 400op37→opacity: 0.37
Breakpoints
One of the most powerful features of Quantum is breakpoint-based media queries.
Pseudo-classes and Pseudo-elements
You can configure set of pseudo-classes and pseudo-elements for which atoms are generated via $pseudos. To emit disjunction of pseudos use comma-separated list.
$pseudos: (hf: (hover, focus));
.c-w-hf:hover,
.c-w-hf:focus {
color: white;
}
Space-separated list defines selector conjunction:
$pseudos: (eh: empty hover);
.c-w-eh:empty:hover {
color: white;
}
Combine those different list types for precise class targeting:
$pseudos: (foo: (active hover, active focus));
.c-w-foo:active:hover,
.c-w-foo:active:focus {
color: white;
}
Grid System
Containers g
As well as in Bootstrap Containers are the most basic layout element and are required when using grid system. Use g-f to create a fixed-width centered responsive layout of columns.
While containers can be nested, most layouts do not require a nested container.
<div class="g g-f">
<!-- Fixed-width grid conteiner -->
</div>
Widths of fixed-width container are stored in $grid-widths.
Rows gr
Rows are horizontal groups of columns that ensure your columns are lined up properly.
<div class="g g-f">
<div class="gr">
<!-- Place columns here -->
</div>
</div>
Columns gc
Content should be placed within columns, and only columns may be immediate children of rows.
Column classes indicate the number of columns you’d like to use out of the possible 12 per row. So if you want three equal-width columns, you’d use SM_gc4. You can change number of columns in grid altering $grid-col-count.
Column widths are set in percentages, so they’re always fluid and sized relative to their parent element.
Columns have horizontal padding to create the gutters between individual columns. Gutters can be configured per every breakpoint via $grid-gutters.
<div class="g g-f">
<div class="gr">
<div class="gc12 SM_gc6">
<!-- Place content here -->
</div>
</div>
</div>
Column Ordering
In addition to column clearing at responsive breakpoints, you may need to reset offsets, pushes, or pulls.
Move columns to the right using [breakpoint_]go(0…12/1) classes. These classes increase the left margin of a column by specified number of columns. For example, MD_go4 moved MD_gc4 over four columns.
Change the order of columns by relatively shifting them to the left with [breakpoint_]gsl(0…12/1) or to the right with [breakpoint_]gsr(0…12/1) classes.
<div class="g g-f">
<div class="gr">
<div class="gc12 SM_gc6 SM_go3">
<!-- Place content here -->
</div>
</div>
</div>
Atom Index
Values for each atom are listed in the order they are listed in generated CSS.
Name Pattern
(1…10/2)Range of possible values from1to10with step2.[breakpoint_]and[-pseudo]Optional breakpoint and pseudo-element or pseudo-class.{key}and{value}Placeholders for map key and map value.
Example [breakpoint_]fw(100…900/100) expands to fw100, fw200 … SM_fw100, SM_fw200 … LG_fw900.
Background
background-color
[breakpoint_]bgc{key}[-pseudo] → background-color: {value}
Specify mapping in $background-colors: (key: value).
background-attachment
bga-f→fixedbga-s→scroll
background-clip
bgcp-bb→border-boxbgcp-pb→padding-boxbgcp-cb→content-boxbgcp-i→inherit
background-image
bgi-n→nonebgi-i→inherit
background-origin
bgo-bb→border-boxbgo-pb→padding-boxbgo-cb→content-box
background-repeat
bgr-n→no-repeatbgr-x→repeat-xbgr-y→repeat-ybgr-s→spacebgr-r→round
background-size
bgz-a→autobgz-ct→containbgz-cv→cover
background-position
bgp-tc→top centerbgp-tl→top leftbgp-cr→center rightbgp-cc→center centerbgp-cl→center leftbgp-br→bottom rightbgp-bc→bottom centerbgp-bl→bottom left
background-position-x
bgpx-r→rightbgpx-c→centerbgpx-l→left
background-position-y
bgpy-t→topbgpy-c→centerbgpy-b→bottom
fill
[breakpoint_]fi{key}[-pseudo] → fill: {value}
Specify mapping in $background-colors: (key: value).
Border
border-color
[breakpoint_]bdc{key}[-pseudo]→border-color: {value}[breakpoint_]bdxc{key}[-pseudo]=bdlc{key},bdrc{key}[breakpoint_]bdyc{key}[-pseudo]=bdtc{key},bdbc{key}[breakpoint_]bdtc{key}[-pseudo]→border-top-color: {value}[breakpoint_]bdbc{key}[-pseudo]→border-bottom-color: {value}[breakpoint_]bdrc{key}[-pseudo]→border-right-color: {value}[breakpoint_]bdlc{key}[-pseudo]→border-left-color: {value}
Specify mapping in $border-colors: (key: value).
border-width
[breakpoint_]bdw{key}→border-width: {value}[breakpoint_]bdxw{key}=bdlw{key},bdrw{key}[breakpoint_]bdyw{key}=bdtw{key},bdbw{key}[breakpoint_]bdtw{key}→border-top-width: {value}[breakpoint_]bdbw{key}→border-bottom-width: {value}[breakpoint_]bdrw{key}→border-right-width: {value}[breakpoint_]bdlw{key}→border-left-width: {value}
Specify mapping in $border-widths: (key: value).
border-style
[breakpoint_]bds{key}→border-style: {value}[breakpoint_]bdxs{key}=bdls{key},bdrs{key}[breakpoint_]bdys{key}=bdts{key},bdbs{key}[breakpoint_]bdts{key}→border-top-style: {value}[breakpoint_]bdbs{key}→border-bottom-style: {value}[breakpoint_]bdrs{key}→border-right-style: {value}[breakpoint_]bdls{key}→border-left-style: {value}
Specify mapping in $border-styles: (key: value).
By default, all available border styles are included. Border style atoms are emitted for every breakpoint what can cause significant increase of outputted CSS file. Be sure to remove unused border styles in order to reduce file size.
border-radius
[breakpoint_]bdr{key}→border-radius: {value}[breakpoint_]bdtr{key}=bdtlr{key},bdtrr{key}[breakpoint_]bdrr{key}=bdtrr{key},bdbrr{key}[breakpoint_]bdbr{key}=bdblr{key},bdbrr{key}[breakpoint_]bdlr{key}=bdtlr{key},bdblr{key}[breakpoint_]bdtrr{key}→border-top-right-radius: {value}[breakpoint_]bdtlr{key}→border-top-left-radius: {value}[breakpoint_]bdbrr{key}→border-bottom-right-radius: {value}[breakpoint_]bdblr{key}→border-bottom-left-radius: {value}
Specify mapping in $border-radiuses: (key: value).
Images
object-fit
of-n→noneof-f→fillof-ct→containof-cv→coverof-sd→scale-downof-i→inherit
Transforms
transform
ts-n→nonets-i→inherittsr(45d…360/45d)→transform: rotate(45deg)…rotate(360deg)tsr(-45d…-360/-45d)→transform: rotate(-45deg)…rotate(-360deg)tss(0…200/25)→transform: scale(0)…scale(2)
Flexible Box Layout
These shortcuts are available if display atom is included.
[breakpoint_]fx-r=d-fx,fxd-r[breakpoint_]fx-rr=d-fx,fxd-rr[breakpoint_]fx-c=d-fx,fxd-c[breakpoint_]fx-cr=d-fx,fxd-cr
flex-direction
[breakpoint_]fxd-r→row[breakpoint_]fxd-rr→row-reverse[breakpoint_]fxd-c→column[breakpoint_]fxd-cr→column-reverse
flex-wrap
[breakpoint_]fxw-n→nowrap[breakpoint_]fxw-w→wrap[breakpoint_]fxw-wr→wrap-reverse
flex-grow
[breakpoint_]fxg(0…10/1) → flex-grow: 0…10
flex-shrink
[breakpoint_]fxs(0…10/1) → flex-shrink: 0…10
flex-basis
[breakpoint_]fxb-a→auto[breakpoint_]fxb-mac→max-content[breakpoint_]fxb-mic→min-content[breakpoint_]fxb-fc→fit-content[breakpoint_]fxb-c→content
justify-content
[breakpoint_]jc-fs→flex-start[breakpoint_]jc-fe→flex-end[breakpoint_]jc-c→center[breakpoint_]jc-sb→space-between[breakpoint_]jc-sa→space-around
align-items
[breakpoint_]ai-fs→flex-start[breakpoint_]ai-fe→flex-end[breakpoint_]ai-c→center[breakpoint_]ai-bs→baseline[breakpoint_]ai-s→stretch
align-content
[breakpoint_]ac-fs→flex-start[breakpoint_]ac-fe→flex-end[breakpoint_]ac-c→center[breakpoint_]ac-sb→space-between[breakpoint_]ac-sa→space-around[breakpoint_]ac-s→stretch
align-self
[breakpoint_]as-a→auto[breakpoint_]as-fs→flex-start[breakpoint_]as-fe→flex-end[breakpoint_]as-c→center[breakpoint_]as-b→baseline[breakpoint_]as-s→stretch
order
[breakpoint_]ord(0…10/1) → order: 0…10
Positioning
float
[breakpoint_]fl-l→left[breakpoint_]fl-r→right[breakpoint_]fl-n→none
clear
cl-l→leftcl-r→rightcl-b→bothcl-n→none
position
pos-s→staticpos-a→absolutepos-r→relativepos-f→fixed
top right bottom left
[breakpoint_]t{key}→top: {value}[breakpoint_]r{key}→right: {value}[breakpoint_]b{key}→bottom: {value}[breakpoint_]l{key}→left: {value}
Specify mapping in $positions: (key: value).
z-index
z(0…10/1)→z-index: 0…10z-a→autoz-i→inherit
Fonts
font-size
[breakpoint_]fz-xxs→xx-small[breakpoint_]fz-xs→x-small[breakpoint_]fz-s→small[breakpoint_]fz-m→medium[breakpoint_]fz-l→large[breakpoint_]fz-xl→x-large[breakpoint_]fz-xxl→xx-large[breakpoint_]fz-lr→larger[breakpoint_]fz-sr→smaller[breakpoint_]fz-i→inherit[breakpoint_]fz{key}→font-size: {value}
Specify mapping in $font-sizes: (key: value).
line-height
lh-n→normallh-i→inheritlh0→0lh1→1lh{key}→line-height: {value}
Specify mapping in $line-heights: (key: value).
font-family
[breakpoint_]fs-s→serif[breakpoint_]fs-ss→sans-serif[breakpoint_]fs-m→monospace[breakpoint_]fs-c→cursive[breakpoint_]fs-f→fantasy[breakpoint_]fs-i→inherit[breakpoint_]fs{key}→font-family: {value}
Specify mapping in $font-families: (key: value).
font-weight
[breakpoint_]fw(100…900/100)→font-weight: 100…900[breakpoint_]fw-n→normal[breakpoint_]fw-b→bold[breakpoint_]fw-br→bolder[breakpoint_]fw-lr→lighter[breakpoint_]fw-i→inherit
font-style
[breakpoint_]fs-n→normal[breakpoint_]fs-i→italic[breakpoint_]fs-o→oblique
font-variant
fv-cl→common-ligaturesfv-apc→all-petite-capsfv-asc→all-small-capsfv-sc→small-capsfv-c→contextualfv-df→diagonal-fractionsfv-sf→stacked-fractionsfv-hf→historical-formsfv-hl→historical-ligaturesfv-i→inheritfv-n→normalfv-tn→tabular-numsfv-pn→proportional-numsfv-pw→proportional-width
font-size-adjust
fza-n → none
font-stretch
fst-n→normalfst-uc→ultra-condensedfst-ec→extra-condensedfst-c→condensedfst-sc→semi-condensedfst-se→semi-expandedfst-e→expandedfst-ee→extra-expandedfst-ue→ultra-expanded
-webkit-font-smoothing
wfsm-a→antialiasedwfsm-sa→subpixel-antialiasedwfsm-n→none
-moz-osx-font-smoothing
mfsm-a→automfsm-g→grayscale
Transitions
transition-property
trp-n→nonetrp-a→all
transition-duration
trd(100ms…1000ms/100ms) → transition-duration: 100ms…1000ms
transition-timing-function
trtf-e→easetrtf-ei→ease-intrtf-eo→ease-outtrtf-eio→ease-in-outtrtf-l→lineartrtf-ss→step-starttrtf-se→step-end
Text
letter-spacing
ls-n→normalls-i→inheritls{key}→letter-spacing: {value}
Specify mapping in $letter-spacings: (key: value).
overflow-wrap
ovw-n→normalovw-b→break-word
text-align
[breakpoint_]ta-l→left[breakpoint_]ta-c→center[breakpoint_]ta-r→right[breakpoint_]ta-j→justify
text-align-last
[breakpoint_]tal-l→left[breakpoint_]tal-c→center[breakpoint_]tal-r→right[breakpoint_]tal-j→justify
text-indent
ti{key} → text-indent: {value}
Specify mapping in $text-indents: (key: value).
text-decoration
[breakpoint_]td-n[-pseudo]→none[breakpoint_]td-u[-pseudo]→underline[breakpoint_]td-o→overline[breakpoint_]td-lt→line-through
text-transform
tt-c→capitalizett-u→uppercasett-l→lowercasett-n→nonett-fw→full-width
white-space
[breakpoint_]ws-n→normal[breakpoint_]ws-p→pre[breakpoint_]ws-nw→nowrap[breakpoint_]ws-pw→pre-wrap[breakpoint_]ws-pl→pre-line
word-break
wob-n→normalwob-ka→keep-allwob-ba→break-all
word-wrap
wow-n→normalwow-bw→break-word
Lists and Counters
list-style
lis-n→nonelis-i→inherit
list-style-position
lisp-in→insidelisp-o→outsidelisp-i→inherit
list-style-type
list-n→nonelist-d→disclist-c→circlelist-s→squarelist-dc→decimallist-dclz→decimal-leading-zerolist-lr→lower-romanlist-ur→upper-romanlist-i→inherit
Colors
color
[breakpoint_]c{key}[-pseudo] → color: {value}
Specify mapping in $colors: (key: value).
opacity
op(0…100/1) → opacity: 0…1
Box Model
box-shadow
bxs{key}[-pseudo] → box-shadow: {value}
Specify mapping in $box-shadows: (key: value).
box-sizing
bxz-cb→content-boxbxz-bb→border-boxbxz-i→inherit
height
[breakpoint_]h{key}→height: {value}[breakpoint_]mah-n→max-height: none[breakpoint_]mah{key}→max-height: {value}[breakpoint_]mih{key}→min-height: {value}
Specify mapping in $heights: (key: value).
width
[breakpoint_]w{key}→width: {value}[breakpoint_]maw-n→max-width: none[breakpoint_]maw{key}→max-width: {value}[breakpoint_]miw{key}→min-width: {value}
Specify mapping in $widths: (key: value).
margin
[breakpoint_]m{key}→margin: {value}[breakpoint_]mx-a→margin-left: auto,margin-right: auto[breakpoint_]mx{key}=ml{key},mr{key}[breakpoint_]my{key}=mt{key},mb{key}[breakpoint_]mt{key}→margin-top: {value}[breakpoint_]mr{key}→margin-right: {value}[breakpoint_]mb{key}→margin-bottom: {value}[breakpoint_]ml{key}→margin-left: {value}
Specify mapping in $margins: (key: value).
padding
[breakpoint_]p{key}→padding: {value}[breakpoint_]px{key}=pl{key},pr{key}[breakpoint_]py{key}=pt{key},pb{key}[breakpoint_]pt{key}→padding-top: {value}[breakpoint_]pr{key}→padding-right: {value}[breakpoint_]pb100p→padding-bottom: 100%[breakpoint_]pb{key}→padding-bottom: {value}[breakpoint_]pl{key}→padding-left: {value}
Specify mapping in $paddings: (key: value).
overflow
ov-v→visibleov-h→hiddenov-s→scrollov-a→auto
overflow-x
ovx-v→visibleovx-h→hiddenovx-s→scrollovx-a→auto
overflow-y
ovy-v→visibleovy-h→hiddenovy-s→scrollovy-a→auto
-webkit-overflow-scrolling
wovs-t→touchwovs-a→auto
visibility
[breakpoint_]v-v→visible[breakpoint_]v-h→hidden[breakpoint_]v-c→collapse
Page
page-break-before
pgbb-a→autopgbb-al→alwayspgbb-av→avoidpgbb-l→leftpgbb-r→right
page-break-inside
pgbi-a→autopgbi-av→avoid
page-break-after
pgba-a→autopgba-al→alwayspgba-av→avoidpgba-l→leftpgba-r→right
User Interface
cursor
cur-a→autocur-d→defaultcur-cm→context-menucur-h→helpcur-p→pointercur-ps→progresscur-w→waitcur-cl→cellcur-c→crosshaircur-t→textcur-al→aliascur-cp→copycur-m→movecur-nd→no-dropcur-na→not-allowedcur-as→all-scrollcur-cr→col-resizecur-rr→row-resizecur-nr→n-resizecur-er→e-resizecur-sr→s-resizecur-wr→w-resizecur-ner→ne-resizecur-nwr→nw-resizecur-ser→se-resizecur-swr→sw-resizecur-ewr→ew-resizecur-nsr→ns-resizecur-neswr→nesw-resizecur-nwser→nwse-resizecur-zi→zoom-incur-zo→zoom-outcur-g→grabcur-gr→grabbingcur-n→none
resize
rz-n→nonerz-b→bothrz-h→horizontalrz-v→vertical
text-overflow
tov-e→ellipsistov-c→clip
user-select
us-n→noneus-t→textus-a→all
Table
border-collapse
bdce-c→collapsebdce-s→separatebdce-i→inherit
caption-side
cps-t→topcps-b→bottom
empty-cells
ec-s→showec-h→hide
table-layout
tbl-a→autotbl-f→fixed
vertical-align
va-sp→superva-t→topva-tt→text-topva-m→middleva-bs→baselineva-b→bottomva-tb→text-bottomva-sb→sub
Miscellaneous
display
d-n→noned-b→blockd-fx→flexd-li→list-itemd-ri→run-ind-i→inlined-itb→inline-tabled-ifx→inline-flexd-ib→inline-blockd-tb→tabled-tcp→table-captiond-tc→table-columnd-tcg→table-column-groupd-thg→table-header-groupd-tfg→table-footer-groupd-tr→table-rowd-trg→table-row-groupd-tcl→table-celld-rb→rubyd-rbb→ruby-based-rbbc→ruby-base-containerd-rbt→ruby-textd-rbtc→ruby-text-container
License
The code is available under MIT licence.