Hi self-disciplined code ogden melon!

: Clippy, bash / zsh commands, CSS Color

CSS Layout (picks)

Grid

grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  • repeat( how-many-times , column-size )
  • auto-fill/auto-fit keyword as first value of repeat() (instead of int): place as many items as possible (defined by their (min-)width) on the row, otherwise wrap them on the next row.
    • fill: let items grow in with to fill up the available spacefit: use (min-)widht of item, remaining space will be left as white space at the end of the row
  • minmax( min max ) as second repeat() valueitem min with in pixel as min-value: «don’t let the item get smaller than this»
    1fr as max-value: «let item be max 1 fraction of the available space», together with the auto-fill keyword this means: «let item be as big as possible within the condition of fitting as many items on the row as possible»

Demo

SASS / SCSS Starter

  • Variabeln: $varname: value; ( x LESS: $ statt @) 
  • Partials: einzubindende .scss files, starten mit einem underscore, z.B. _vars.scss, durch wird daraus kein .css generiert.
  • Import: Wie LESS; @import ‚filename‘ => ohne Endung, ohne underscore für Partials
  • Mixins:
    • Definition: @mixin mixin-name($param){ … } 
    • Verwendung: .class { @include mixin-name(10px); }
  • placeholder class %class-name { … } wird nur zu css konvertiert wenn es extended wird
  • @extend: .random-class{ @extend %some-styles; … ; } . .random-class erbt nun die werde von %some-styles (bzw. wird in einer css definition, mit allen anderen Klassen, die %some-styles verwenden gruppiert).
  • operators wie LESS ( +, – , *, / , %)

Examples / snippets

loop trough map

$color-map: (
	bright: $color-bright,
	key-1: #4C38D5,
	key-2: #474DE1,
	dark: #000
);

@each $id, $color in $color-map {
	[data-start="#{$id}"] {
		--color-start: #{$color};
	}
	[data-end="#{$id}"] {
		--color-end: #{$color};
	}
}

Example Output

[data-start="key-2"]{
   --color-start: #474DE1;
}
[data-end="key-2"]{
   --color-end: #474DE1;
}

multidimensional maps

$color-themes: (
  ('dark', cornflowerblue, #191970, $darkblue'),
  ('sunrise', orange, $yellow, #daa520),
  ('light', $gray-600, #eee, smoke),
);

@each $theme in $color-themes {
   $name: nth($theme,1);
   .theme-#{$color-themes.index($name)} {
     color: #{nth($theme,2)};
     backgound: #{nth($theme,3)};
     border-color: #{nth($theme,4)};
   }
}

Example Output

.theme-dark {
  color: cornflowerblue;
  background: #191970;
  border-color: #00008b;
}

When prefering inded themes (e.g. theme-1) use a @for loop:

@for $i from 1 through length($color-themes) {
   theme-#{$i} {
     $theme: nth($color-themes,$i); // <- map theme
     color: #{nth($theme,2)};
     ...
   }
}

extending

SCSS:

.mw-100p {
  max-width: 100%;
}
.thumbnail {
  @extend .mw-100p;
  border-radius: 50%;
}

Outputs (CSS):

.mw-100p, .thumbnail {
  max-width: 100%;
}

.thumbnail {
  border-radius: 50%;
}

See: Sass: @extend

References

CSS properties i have overlooked

resize

resize: none | both | vertical | horizontal | ...

→ makes element resizable (like texbox). Great for responsive demo. doc, caniuse


text-decoration styling

text-decoration: -line -style -color

/* shorthand example */ 
text-decoration: undeline solid red

keyword: text-decoration styling. example, caniuse

text-decoration-skip: ink

clears decenders etc. doc and more values: mdn, css-tricks . caniuse


display: contents | flow-root

  • contents: makes element 'transparent' as if it does not exist in the dom => children of element become the same level => eg. as substitute for sub-grid, at the time FF only: caniuse
  • flow-root: elemnt becomes container box => same result as clearfix-hack. caniuse

CSS Layout (picks)

Grid

grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  • repeat( how-many-times , column-size )
  • auto-fill/auto-fit keyword as first value of repeat() (instead of int): place as many items as possible (defined by their (min-)width) on the row, otherwise wrap them on the next row.
    • fill: let items grow in with to fill up the available space
    • fit: use (min-)widht of item, remaining space will be left as white space at the end of the row
  • minmax( min max ) as second repeat() value
    • item min with in pixel as min-value: «don't let the item get smaller than this»
    • 1fr as max-value: «let item be max 1 fraction of the available space», together with the auto-fill keyword this means: «let item be as big as possible within the condition of fitting as many items on the row as possible»

Demo:

Item 1
Item 2
Item 3
Item 4
Item 5

flexbox

  • Fixed-with item: flex: 0 0 230px;
    • 0 = don’t grow (shorthand for flex-grow)
    • 0 = don’t shrink (shorthand for flex-shrink)
    • 230px = start at 230px (shorthand for flex-basis)
    • source: stackoverflow
  • margin-left: auto (or any other direction) pushes the element (and all successors) to the farthest righthand side (or any other side) leaving a gap between the item and its precursor.

nicer underlines

better customizable underlines with descender clearing option.

LESS mixin:

@background-color: #fff;
@link-color: #333;
@link-color-active: #55abad;
@link-underline-color: @link-color;
@link-underline-color-active: @link-color-active;
@link-underline-width: 1px;
@link-underline-offset: 2px;
@breaking-underlines: true;

.underline(@color: @link-underline-color, @weight: @link-underline-width, @offset: @link-underline-offset){
	text-decoration: none;
	background-image: linear-gradient(to top, transparent, transparent @offset, @color @offset, @color (@offset + @weight), transparent (@offset + @weight));
	& when (@breaking-underlines){
		text-shadow: -1px -1px 0 @background-color, 1px -1px 0 @background-color, -1px 1px 0 @background-color, 1px 1px 0 @background-color;
	}
}

(mehr …)

Body at least 100% height

Set body height 100% Browser height – or higher if the content is longer.

html { 
  height: 100%; 
}

body {
  height: auto; min-height: 100%; 
}

For IE6 support, set height 100% aswell to the body and !important height: auto;

body { 
  height: auto !important; 
  height: 100%; /* IE6 */ 
  min-height: 100%; 
}

Source

If you need a child element of the body to have the min-heigt, set the bodys height to 1px.
! Note ! : In some cases the body doesn’t scale to min 100% height anymore.

body { 
  height: 1px; 
  min-height: 100%; 
}

LESS Kickstart

– Just a reminder –

For Detailed Infos see: LESS Language Features.

  • Nested Rules    #header { color: black; .nav { color:red; } }
  • Nested MediaQueries
    • & : represents the current selector parent
  • Functions
  • scope  as in other languages; first locals then globals. @var; /* global */ .elem{ @var; /* local */ }

Vars

  • Selectors   @mySelector: banner; .@{mySelector} { /*…*/ } outputs: .banner { /*…*/ }
  • URLs/Paths  @images: „../img“; .logo {background: url(„@{images}/logo.png“); }   (works within @import)
  • Properties   @poperty: color; .elem{ @{property}: red; }  outputs: .elem { color:red; }

:extend

  • syntax  nav { &:extend(.menu); color:red; } .menu { font-weight: bold; }   outputs nav { color: red; } .menu, nav { font-weight: bold; }
    •   .a:extend(.b) {}  == .a { &:extend(.b); }

( … )

Parametric Mixins

  •   .elem(@col){ color: @col; } .btn{ .elem(red); }
  • default value:  .elem( @col: blue ) { color: @color; }
  • multiple param:  .mixin(@color: black; @margin: 10px; @padding: 20px) {color: @color; margin: @margin; padding: @padding; }
  • @arguments contains all the arguments [ .mixin( @arg1; @arg2; … ) ] passed, when the mixin was called.
  • Pattern matching:
    .mixin(dark; @color){ color: darken(@color, 10%); } 
    .mixin(light; @color){ color: lighten(@color, 10%); }
    
    @switch: light;
    .elem { .mixin(@switch, red); } //outputs a lighten red as color

     

Mixin Guards – less’s if/else

  • .mixin (@a) when (lightness(@a) >= 50%) {
      background-color: black;
    }
    .mixin (@a) when (lightness(@a) < 50%) {
      background-color: white;
    }
    
    // .elem { .mixin(#ccc); } outputs background-color: black;
    // .elem { .mixin(#333); } outputs background-color: white;
  • operators: : >, >=, =, =<, <, true
  • CSS guards:  button when (@my-option = true) { color: white; }

Parent Selector

  • & :
    .button {
      &-ok { // .button-ok 
        …;
      }
      &-cancel { // .button-cancel
        …;
      }

     

JavaScript

JavaScript evaluation JavaScript expressions can be evaluated as values inside .less files. We recommend using caution (…)  However, if you still want to use JavaScript in .less, this is done by wrapping the expression with back-ticks

source: lessc doc

@var: `Math.random()`;

 

Lintinng

CSS

  • Doiuse – checks CSS file for Browsersupport against caniuse.com (command line / js)

 

JS

  • JSCC – online javascript compatibility checker (copy&paste)

CSS Units

7 CSS Units You Might Not Know About (tuts+)