jonka Piotr Delikat 9 vuotta sitten
1392
Lisää tämän kaltaisia
collapsing height
setting a ClearFix
pro solution
give a parent element the .group
.group:after{content: ""; display: table; clear: both; }
clear: both;
clears both site of a collapsing space
overflow
not recomendet solution
:auto;
tell the browser to account the height of a floats
sets elements to initial scale of device
good for mobile media queries
.warper,
.nav li {
width: initial;
height: initial;
float: initial;
}
like a block element, but in a flow of it's surroundings
sets elements in the flow of content
default for anchor elements
block element takes all available space of a parent element
default option of displaying
turn of displaying of an element
// Screen reader text
.srt {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
for clearnig list decotarion
line-height : ($base__line/$base__font_size);
:focus
when you interact with keyboard for ex.(by tab)
implies that user is redy for interaction
:active
not only for links or buttons
most common in nav section
:hover
:visited
:link
not visited links
good for icons and small graphic elements
content: "blank/text"; / content: url(.../img.svg);
content is obligatory
gives us extra layers to work with :)
they are visible to user, but do not appear in the HTML source code
sets the virtual element befor or after selected element
most specific
less sepcific
header span {
color : white;
font-size : 26px;
}
only nestedElement will be changed
by default list are indented left
padding-left: 0;
by default list style is outsite the
list-style-position
list-style-position
:inside;
to change it
:none;
:decimal-leading-zero;
:square/circle/decimal/lover-latin/etc..;
rounded corners of the element
: %;
50% is a circle
border-top : 2px solid blue;
background-image: #45690 url('path/image.jpg') no-repeat center / cover;
:x y;
:20% 50%;
:right bottom;
:center center;
= :center;
left top corner by default
:no-reapeat;
:repeat-y;
only on y axis
:repeat-x;
only on x axis
it's :repeat; by default
relative to the element size
:cover;
best for full background images
fits the image proportionally to the full size of element
:
it is repaeted horizontaly/verticaly by default
: url('path/image.jpg');
it is good practice to set the contrast to content color. Even with bg-img in case of problems with displaying it
it can be universal for whole project
* {
box-sizing: border-box;
}
calculate width and height substracting box model values
helps us with calculation of size of elements
img {max-width: 100%;}
px are for precise elements like graphics/icons
with % element is relative to the parent element
states at mobile
collapse at mobile class
is displayed at mobile class
_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;
}
}
mixin
// 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}'."
}
}
variables fro breakpoints
_config.scss
// Breakpoints
$brkpoint-sm : 1px;
$brkpoint-md : 768px;
$brkpoint-lg : 1100px;
usage
class="grid__col--12"
full width in the grid
class="grid"
center the content
we also need to specify a container for grid
_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;
}
}
mixin to adjust column siblings
// Adjacent sibling margins
@mixin doubly($margin: 1em) {
& + & {
margin-left: $margin;
@content;
}
}
loop to generate calsses
_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
.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%; }
@function to count context
_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;
}
nessesery variables
_config.scss
// Grid
$g-col-width : 65px;
$g-gutter-width : 20px;
$g-col-cound : 12;
$g-cont-max-w : 1050px;
body {
font-size : $base__font-size;
line-height : ($base__line/$base__font_size)
font-family : $font-family--primary;
}
map-get(map-get($mapName, value) nestedValue);
pallets of colors
grey & black
$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
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);
color : map-get(map-get($palettes, grey) x-grey);
we need @mixin to genetare classes
@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; } } }
we can make class first in css, and use it in HTML later
$ui-colors: (
default : $fountain-blue,
success : $emerald,
error : $sunglo,
warning : $coral,
info : $purple-majesty
);
@error
ex.
@else {
@error "'{$pos}' is an invalid argument.";
}
shows error in css output (and browser)
@warn
shows warrning in the console
// Call the color palette modifiers
@function palette($pallete, $shade: 'base') {
@return map-get(map-get($palettes, $pallete), $shade);
}
//Calculate pixels to em values
@function em($target, $context: $base__font_size) {
@return ($target / $context) * 1em;
}
font-size : em(42px);
usage for H1
h1 {
font-size : em(42px);
line-height : (46px / 42px);
margin-bottom : em(70px, 42px);
}
//Import if Google Fonts URL is defined
@if variable-exists(font-url--google) {
@import url($font-url--google);
}
@extend .ruleName;
@extend %extensionName;
you can include %extends and rules from other files onto every element
really helpful to make Sass DRY
file name for functions and mixins
generating pseudo elements shapes with @error
@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
%pseudos {
display: block;
content: '';
position: absolute;
}
background-image
@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
@include img-replace('logo.svg', 115px, 45px, inline-block);
like a loops
@each $parOne, $parTwo in $mapName {.class-- #{$parOne} { cssKey : $parTwo; }}
to create classes for ex.
//Color maps
@each $theme, $color in $ui-colors {
.btn--#{$theme} {
background-color : $color;
}
}
like a functions
//path to images
$path--rel : "../img";
//letter-space
$letter-space : 1px;
//font size
$base__line : 24px;
$base__font-size : 16px;
//color usage
$color-shadow : rgba($black, .2);
$color-accent : $purple-majesty;
$color-primary : $black;
//descriptive Base Colors
$grey : #797e83;
$black : #0b0b0b;
more fancy black :)
$white : #fff;
//font weight
$font-weight--thin
etc.
$font-weight--thin : 100;
$font-weight--light : 300;
$font-weight--medium : 400;
$font-weight--bold : 700;
$font-weight--ultra-bold : 900;
//font stack
of some more clever fontstack
$font-family--primary
$font-family--primary : 'Lato', 'Helvetica Neue','Helvetica','Arial', 'sans-serif';
//font url
$font-url--google
$font-url--google : 'http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900';
BEM nameing convention
good practice
good name for variables file