CSS

CSS

SASS

SASS

$variables

_config

good name for variables file

$value-desc--valVariation : property;

good practice

BEM nameing convention

fonts

//font url

$font-url--google

r

$font-url--google : 'http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900';

a

//font stack

//font weight

colors

//descriptive Base Colors

//color usage

$color-primary : $black;

$color-accent : $purple-majesty;

$color-shadow : rgba($black, .2);

text

//font size

$base__font-size : 16px;

$base__line : 24px;

//letter-space

$letter-space : 1px;

images

//path to images

@mixin

use it

like a functions

like a loops

usefull mixins

background-image

r

@mixin img-replace($img, $w, $h, $disp: block ) { background-image: url('#{$path--rel}/#{$img}'); background-repeat: no-repeat; width: $w; height: $h; display: $disp;}

ex. usage

generating pseudo elements shapes with @error

@mixin

r

@mixin p-el( $el, $el-w: null, $el-h: null) { @if $el == "before" or $el == "after" { &:#{$el} { @extend %pseudos; width: $el-w; height: $el-h; @content; } } @else { @error "'#{$el}' is not a valid pseudo-element."; }}

@content //for pseudo elements

r

%pseudos { display: block; content: ''; position: absolute;}

function()

_utilities

file name for functions and mixins

@extend

you can include %extends and rules from other files onto every element

really helpful to make Sass DRY

@extend %extensionName;

@extend .ruleName;

@if variable-exist() {};

@function functionName($parOne, $parTwo : $dafaultValue) {};

usefull functions

//Import if Google Fonts URL is defined

r

@if variable-exists(font-url--google) { @import url($font-url--google);}

//Calculate pixels to em values

r

@function em($target, $context: $base__font_size) { @return ($target / $context) * 1em;}

// Call the color palette modifiers

r

@function palette($pallete, $shade: 'base') { @return map-get(map-get($palettes, $pallete), $shade);}

debbuging

@warn

shows warrning in the console

@error

shows error in css output (and browser)

ex.

r

@else { @error "'{$pos}' is an invalid argument."; }

Sass Maps

like objects in any other language

color

ex.

r

$ui-colors: ( default : $fountain-blue, success : $emerald, error : $sunglo, warning : $coral, info : $purple-majesty );

we can make class first in css, and use it in HTML later

we need @mixin to genetare classes

r

@each $theme, $color in $ui-colors { .btn--#{$theme} { background-color : $color; }}

even more modular

@mixin bg-colors($map) {
@each $theme, $color in $map {
&--#{$theme} {
background-color : $color;
}
}
}

nested maps

pallets of colors

grey & black

r

$palettes: (grey: ( xx-light : lighten($grey, 43%), x-light : lighten($grey, 35%), light : lighten($grey, 12%), base : $grey, dark : darken($grey, 8%), x-dark : darken($grey, 16%) ),black: ( light : lighten($black, 10%), base : $black, dark : darken($black, 10%), ) );

how to get it

color : map-get(map-get($palettes, grey) x-grey);

of write a function :)

@function palette($pallete, $shade: 'base') {
@return map-get(map-get($palettes, $pallete), $shade);
}

call it with

color: palette(grey, x-dark);

map-get(map-get($mapName, value) nestedValue);

map-get($mapName, value);

document formating

body

r

body { font-size : $base__font-size; line-height : ($base__line/$base__font_size) font-family : $font-family--primary;}

Methodology

Block Element Modifier

naming convention based on class

help us to write clear and easy to understand CSS

of course not everything can be taken under this nameing convention

ex .site-logo

downsite of BEM approach is lots of classes in html

but

readability is more important

.block__element--modifier

.list {}

.list__item {}

.list__item--block {}

Block = root of the element

highest level of abstraction

Element = child of the root element

Modifier = Styles and Variations

Sass way

BEM @mixin

r

@mixin e($element) { &__#{$element} { @content; }}@mixin m($modifier) { &--#{$modifier} { @content; }}

navigation

ex

r

.nav {margin-top: em(20px);margin-bottom: em(30px);&__item {display: inline-block;margin: 0 em(12px);a {font-size: em(18px);font-weight: $font-weight--light;color: palette(grey);display: block;padding: em(8px, 18px);}&--current a {color: palette(black);border-color: $color-primary;}}}

with @extend

r

_extend.scss// Nav Items%nav-item-disp { display: inline-block; margin: 0 em(12px);}%nav-item-link { font-size: em(18px); font-weight: $font-weight--light; display: block; padding: em(8px, 18px); border-bottom: 1px solid transparent;}%nav-item-on { color: palette(black); border-color: $color-primary;}.nav { margin-top: em(20px); margin-bottom: em(30px); @include e(item) { @extend %nav-item-disp; a { @extend %nav-item-link; color: palette(grey); &:hover { @extend %nav-item-on; } } @include m(current) { @extend %nav-item-disp; a { @extend %nav-item-link; @extend %nav-item-on; } } }}

output 4 classes

r

.nav.nav__item.nav__item a //active only on anchor elements.nav__item--current a //active only on selected anchor element

headline

ex.

r

.headline { &-primary { @extend %hdln-prim; margin-bottom: em(70px, 42px); } &-secondary { @extend %hdln-sec; margin-bottom: em(22px, 24px); }}

@extension

r

// Headlines%hdln-prim { font-weight: $font-weight--light; font-size: em(42px); line-height: (46px / 42px); margin-bottom: em(70px, 42px); color: palette(grey, x-dark); margin-top: 0;}%hdln-sec { font-family: $font-family--secondary; font-weight: $font-weight--thin; font-size: em(24px); color: palette(grey, light); letter-spacing: $letter-space;}

form

ex.

r

.form { @include e(label) { @include m(hidden) { @extend .srt; } dispaly: block; margin-bottom: em(10px); } @include e(input) { width: 100%; font-size: em(18px); padding: em(15px, 18px); margin-bottom: em(20px, 18px); border-bottom: 6px solid palette(grey, x-light); border-radius: $br--default; background: palette(grey, xx-light); color: palette(black, dark); font-weight: $font-weight--light; &:focus { border-color: $color-primaty; } } @include e(btn) { @extend %btn; background-color: $color-primary; }}

classes

r

.form.form__lable.form__label--hidden //for screan readers.form__input // :active.form__btn //for submit button

Scalable and Modular Architecture for CSS

to organize and structure CSS on any scale

more like a architecture style guid

divdes project into categories

base

how the elements looks by default

reset styles

use only element selectors

give them default values

no classes and id-s

layout

major sections of the page

header, footer, sidebar, grid

wrappers for other componenets

some developers avoid this category

panel rules for positioning header and footer

r

.panel { @extend %panel-default; @include m(centered) { @extend %panel-default; @extend %center-align; } @include m(padded) { @extend %panel-padding; @include m(centered) { @extend %center-align; @extend %panel-padding; } }}

@extends

r

// Panels%panel-default { padding-top: em(30px); padding-bottom: em(20px);}%panel-padding { padding-top: em(80px); padding-bottom: em(34px);}// Center alignment%center-align { text-align: center;}

modules

majority of project styles

each module as a separate, reusable component

states

style for element states

:hidden, :active, :expand etc.

themes

diffrent colors and images for diffrent color themes

default category

like for wordpress themes

optionaly

utilities

_mixins

_functions

_config

_helpers

application.scss

@imports

categoryName/_index.scss

from the folders of categories

which contain all the partial files

order of imported parts is important!

sassy - SMACSS based starter for a project

Grid System

nessesery variables

r

_config.scss// Grid$g-col-width : 65px;$g-gutter-width : 20px;$g-col-cound : 12;$g-cont-max-w : 1050px;

@function to count context

r

_functions.scss// Set the "context" width for the grid@function g-context($g-col-width, $g-col-count, $g-gutter-width) { $g-context : ($g-col-width * $g-col-count) + ($g-gutter-width * ($g-col-count - 1)); @return $g-context;}

loop to generate calsses

r

_grid-columns.scss// Calculate grid columns@media (min-width: 769px) { @for $i from 1 through $g-col-count { $context: g-context($g-col-width, $g-col-count, $g-gutter-width) !global; $target: ($g-col-width * $i) + ($g-gutter-width * ($i - 1)); //Generate column modifier classes .grid__col--#{$i} { width: percentage($target / $context); } }}// Column Styles[class^="grid__col--"] { @media (min-width: 1px) and (max-width: 768px) { margin-top: em(12px); margin-bottom: em(12px); } @media (min-width: 769px) { @include doubly(percentage($g-gutter-width / $context)); float: left; min-height: 1px; padding-left: 10px; padding-right: 10px; &:last-of-type { float: right; } }}

output

r

.grid__col--1 { width: 6.5%; }.grid__col--2 { width: 15%; }.grid__col--3 { width: 23.5%; }.grid__col--4 { width: 32%; }.grid__col--5 { width: 40.5%; }.grid__col--6 { width: 49%; }.grid__col--7 { width: 57.5%; }.grid__col--8 { width: 66%; }.grid__col--9 { width: 74.5%; }.grid__col--10 { width: 83%; }.grid__col--11 { width: 91.5%; }.grid__col--12 { width: 100%; }

mixin to adjust column siblings

r

// Adjacent sibling margins@mixin doubly($margin: 1em) { & + & { margin-left: $margin; @content; }}

we also need to specify a container for grid

r

_grid-container.scss.grid { @extend %clearfix; @extend .centered; width: 90%; // Make nested grid container 100% [class*="grid__col--"] > & { width: 100%; } // Set a max-width grid container @media(min-width: 1100px) { max-width: $g-cout-max-w; }}

usage

class="grid"

center the content

class="grid__col--12"

full width in the grid

Modular Media Queries

variables fro breakpoints

r

_config.scss// Breakpoints$brkpoint-sm : 1px;$brkpoint-md : 768px;$brkpoint-lg : 1100px;

mixin

r

// Media queries@mixin mq($break) { @if $break == "small" {@media (min-width: $brkpoint-sm) and (max-width: $brkpoint-md) { @content; } } @else if $break == "medium" {@media (min-width: $brkpoint-md + 1) { @content; } } @else if $break == "large" {@media (min-width: $brkpoint-lg) { @content; } } @else {@error "Whoops! No value could be retrieved for '#{$break}'." } }

states at mobile

is displayed at mobile class

r

_grid_display==========================================================================// Grid display// ==========================================================================.is-displayed-mobile { @include mq(small) { display: block; @at-root (with: media) { .is-hidden-mobile { display: none; } } } @include mq(medium) { display: none; }}

collapse at mobile class

styling

height

:<lenght>/%;

with % element is relative to the parent element

px are for precise elements like graphics/icons

width

:<lenght>/%;

with % element is relative to the parent element

px are for precise elements like graphics/icons

max-width

prevents the element from beeing widther than some px values

for good readability on big screens like SamartTV or Mac

making images responsive!

img {max-width: 100%;}

box-sizing

:border-box;

helps us with calculation of size of elements

calculate width and height substracting box model values

it can be universal for whole project

r

* {box-sizing: border-box;}

background

it is everyfing exept the margin

everyfing has a transparent background by default

background-color

it is good practice to set the contrast to content color. Even with bg-img in case of problems with displaying it

background-image

: url('path/image.jpg');

it is repaeted horizontaly/verticaly by default

background-size

:<lenght>/% ;

:cover;

fits the image proportionally to the full size of element

best for full background images

relative to the element size

background-repeat

it's :repeat; by default

:repeat-x;

only on x axis

:repeat-y;

only on y axis

:no-reapeat;

background-position

left top corner by default

:x y;

:center center;

= :center;

:right bottom;

:<lenght>/%;

:20% 50%;

it can be write in one line

background-image: #45690 url('path/image.jpg') no-repeat center / cover;

border

ex.

border-radius

: %;

50% is a circle

rounded corners of the element

clip

:rect(0,0,0,0);

list-style

list-style-type

:square/circle/decimal/lover-latin/etc..;

:decimal-leading-zero;

:none;

by default list style is outsite the <li> element

list-style-position

:inside;

to change it

by default list are indented left

padding-left: 0;

to change it

selections

text

line-height

can be unitless

Sass usage for line heights

r

line-height : ($base__line/$base__font_size);

font-size

font-family

font-style

:italic;

:bold;

text-align

font-weight

letter-spacing

text-decotarion

none

for clearnig list decotarion

class for screen reader text

r

// Screen reader text.srt { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px;}

positioning

Other

comments

/* commented */

structure

basic structure of document

listy

uporządkowane

<ol> <li>...</li> </ol>

domyślnie z numerami, istotna kolejność

CSS list-style-type: ...;

nieuporządkowane

<ul> <li>...</li> </ul>

domyślnie z kropkami, kolejność mniej ważna

<li>...</li>

element listy

listy definicji

<dl>

lista

<dt>

definicja

<dd>

termin

łącza

<a href=""></a>

względne w stosunku do bazowego index.html

../subsite.html

nadrzędny katalog

../../subsite.html

nadrzędny x2 katalog

do poczty

<a href="mailto:email@frank.com>

otwieranie w nowym oknie

<a href="" target="_blank"></a>

przeniesienie w inne miejsce na stronie

zamiast przewijania

<a href="#id elementu"></a>

tak samo można kierować do okteślonych miejsc na innych stronach

<a href="link.html#id elementu"></a>

obrazy

<img src="image.jpg" alt=" wymagany tekst alternatywny" title="tytuł">

<figure><img ...><figcaption>Podpis Obrazu</figcaption></figure>

nowy element HTML5, pozwala na powiązanie obrazu z opisem

tabele

<table></table>

nagłówek tablei

<thead></thead>

<tr></tr>

wiersz

<th scope="row"></th>

nagłówek do rzędów

<th scope="col"></th>

body tabeli

<tbody></tbody>

<td></td>

komórka

łączenie komórek dwóch kolumn w jednym rzędzie

<td colspan=”2”>...</td>

łacznenie komórek dwóch rzędów w kolumnie

<td rowspan=”2”>...</td>

footer tabeli

<tfoot></tfoot>

formularze

<form></form>

<input></input>

type="text" // "password" // "email" // file // submit // image // hidden // date // url // search

maxlenght=23;

określa max liczbę znaków jakie można wpisać

name="identyfikacjaDlaSerwera"

id="dlaLabel"

radio buttons

type="radio"

tylko jedna z opcji możliwa

value="nazwaButtona"

checked="checked"

domyśłnie zaznaczony

checkbox

type="checkbox"

wiele opcji możliwych

<select></select>

<option value="nazwaOpcji"></option>

selected=”selected”

do wyboru domyślnej opcji

multiple

do umożliwienia zaznaczenia kilku opcji

placeholder="wartośćZnikaPoKilknięciu"

method='get' // 'post' // inna metoda

action="..."

link do strony wysyłjącej lub odbierającej informacje

<textarea>Text w textarea</textarea>

obszerny obszar do wpisania textu

<label></label>

etykiety do formularzy

for="IdFormularza"

grupowanie formularzy

<fileset><legend>Nazwa formularza<legend></fileset>

walidacja formularzy

<input type="email" name="poczta" required></input>

<form novalidate></form>

by wyłączyć

inne

<button></button>

semantic

additional meaning like bold, italic etc.

<sup>

indeks górny

r

E = mc<sup>2</sup>

<sub>

indeks dolny

r

CO<sub>2</sub>

</br >

następny akapit

r

</hr >

linia pomiędzy dwoma akapitami

ważne dla tekstu i czytników ekranowych

<strong>

pogrubienie tekstu, większy nacisk na fragmet tekstu

<em>

domyślnie- kursywa, większy nacisk na znaczenie fragmentu

cytaty

<q>

krótsze cytaty wewnątrz tekstu

<blockquote>

dłuższe cytaty jako osobne paragrafy

udostępniają atrybut cite="..."

dla podania linka do źródła cytatu

<cite></cite>

odwołanie się do książki filmu etc.

sktóry

<abbr></abbr>

atrybut title="..."

pozwala podać znaczenie sktótu

<acronym></acronym>

definicje

<dfn></dfn>

gdy poraz pierwszy wyjaśniamy znaczenie jakiegoś pojęcia

adress

<address></address>

rest

wiadomość do przeglądarki, ze to dokument HTML5

<!DOCTYPE html>

komentarze w HTML

<!-- Nieaktywna treść -->

id=""

calss=""

elementy blokowe

<div></div>

<iframe></iframe>

np. ramka z google maps

seamless

blokuje wyświetlanie pasków przewijania

frameborder

elementy wierszowe

<span></span>

jak div grupuje elementy, ale w jednym wierszu, a nie w całym bloku

można potem dowolnie przerobić fragment tekstu w CSS

<meta />

informacje o stronie zawarte w <head>

może być bez tagu zamykającego

name="nazwaMetaTagu"

description

keywords

oddzielone przecinkami

bez wpływu na pozycje w wyszukiwarce

robots

można wygonić roboty wyszukujace od strony

noindex

mają nie indeksować strony w wyszukiwarkach

nofollow

mają nie indeksować jedynie łączy umieszczonych na stronie

content=" "

wartość metatagu

<meta http-equiv=”pragma”
content=”no-cache” />

zabrania wyszukiwarka zapisywać strony na kompie użytkownika

Subtopic