Skip to content

Instantly share code, notes, and snippets.

@sixertoy
Last active May 18, 2018 08:36
Show Gist options
  • Select an option

  • Save sixertoy/c89db236e80322bf238f8c21457e24b5 to your computer and use it in GitHub Desktop.

Select an option

Save sixertoy/c89db236e80322bf238f8c21457e24b5 to your computer and use it in GitHub Desktop.
A Collection of CSS Snippets

A Collection of CSS Snippets

  • Flexbox grid 4
  • Vertical Centered Elements
  • Eric Meyer's Reset 2.0
  • Preloader
  • Margin & Padding (SASS)
  • Speech Bubble (SASS)
$flexs: (
0,
1,
2,
3,
4,
5
);
@each $flex in $flexs {
.flex-#{$flex} {
flex: #{$flex};
display: flex;
}
}
/* --------------------------------------------
FLEX Alignments
-------------------------------------------- */
.flex-columns {
flex: 1;
display: flex;
flex-direction: row;
}
.flex-rows {
flex: 1;
display: flex;
flex-direction: column;
}
.flex-reverse {
&.flex-columns {
flex-direction: row-reverse;
}
&.flex-rows {
flex-direction: column-reverse;
}
}
$wraps: (
wrap,
nowrap,
wrap-reverse
);
@each $wrap in $wraps {
.flex-#{$wrap} {
flex-wrap: $wrap;
}
}
.flex-wrap {
flex-wrap: wrap;
}
$types: (
items: align-items,
flex: justify-content,
content: align-content
);
@each $key, $value in $types {
.#{$key}-end {
#{$value}: flex-end;
}
.#{$key}-start {
#{$value}: flex-start;
}
.#{$key}-center {
#{$value}: flex-center;
}
}
$spaces: (
evenly,
around,
between
);
@each $space in $spaces {
.flex-#{$space} {
justify-content: space-#{$space};
}
}
.items-stretch {
align-items: stretch;
}
.items-baseline {
align-items: baseline;
}
.content-stretch {
align-content: stretch;
}
.content-around {
align-content: around;
}
.content-between {
align-content: between;
}
/* flex grid 4 items with 12px of margin around item */
.flexgrid-4 {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.flexgrid-4 > * {
margin: 12px;
flex: 0 0 auto;
width: calc(25% - 24px);
}
$spaces: (
0,
3,
7,
12,
20,
24,
40,
60,
80,
100,
120
);
$sides: (
all,
topbottom,
leftright,
top,
left,
right,
bottom
);
@each $space in $spaces {
@each $side in $sides {
@if $side == 'all' {
.m#{$space} {
margin: #{$space}px;
}
.p#{$space} {
padding: #{$space}px;
}
}
@else if $side == 'topbottom' {
.my#{$space} {
margin: #{$space}px;
}
.py#{$space} {
padding: #{$space}px;
}
}
@else if $side == 'leftright' {
.mx#{$space} {
margin: #{$space}px;
}
.px#{$space} {
padding: #{$space}px;
}
}
@else {
.m#{str-slice($side, 0, 1)}#{$space} {
margin-#{$side}: #{$space}px;
}
.p#{str-slice($side, 0, 1)}#{$space} {
padding-#{$side}: #{$space}px;
}
}
}
}
.loader {
height: 4px;
width: 100%;
overflow: hidden;
margin-bottom: 7px;
position: relative;
background-color: #DDD;
}
.loader::before {
content: "";
height: 4px;
left: -200px;
width: 200px;
display: block;
position: absolute;
background-color: #2980B9;
animation: loading 2s linear infinite;
}
@keyframes loading {
from {
width: 30%;
left: -200px;
}
50% {
width: 30%;
}
70% {
width: 70%;
}
80% {
left: 50%;
}
95% {
left: 120%;
}
to {
left: 100%;
}
}
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
// BUBBLE SPEECH
// -----
// @source: https://leaverou.github.io/bubbly/
//
// Usage
// -----
// .speech-bubble-{top,bottom,left,right}
// + optionnal arrow design .speech-{io,oi}
//
$speech-bubble-size: 1rem;
$speech-bubble-color: #FFFFFF;
$speech-bubble-radius: 0.3rem;
.speech-bubble {
position: relative;
background: $speech-bubble-color;
border-radius: $speech-bubble-radius;
}
.speech-bubble::after {
width: 0;
height: 0;
content: '';
position: absolute;
border-style: solid;
border-color: transparent;
border-width: $speech-bubble-size;
}
$sides: (
top,
left,
right,
bottom
);
@each $side in $sides {
.speech-bubble.speech-#{$side}::after {
@if ($side == 'top') or ($side == 'bottom') {
left: 50%;
margin-left: -$speech-bubble-size;
/* ----- colors ----- */
@if ($side == 'top') {
border-bottom-color: $speech-bubble-color;
}
@else if ($side == 'bottom') {
border-top-color: $speech-bubble-color;
}
}
@else if ($side == 'left') or ($side == 'right') {
top: 50%;
margin-top: -$speech-bubble-size;
/* ----- colors ----- */
@if ($side == 'left') {
border-right-color: $speech-bubble-color;
}
@else if ($side == 'right') {
border-left-color: $speech-bubble-color;
}
}
#{$side}: 0;
border-#{$side}: 0;
margin-#{$side}: -$speech-bubble-size;
}
/* ----- arrow options ----- */
@if ($side == 'top') or ($side == 'bottom') {
.speech-bubble.speech-#{$side}.speech-io::after {
border-right: 0;
}
.speech-bubble.speech-#{$side}.speech-oi::after {
border-left: 0;
}
}
@else if ($side == 'left') or ($side == 'right') {
.speech-bubble.speech-#{$side}.speech-io::after {
border-bottom: 0;
}
.speech-bubble.speech-#{$side}.speech-oi::after {
border-top: 0;
}
}
}
h1 {
font-size: 1.786em;
}
h2 {
font-size: 1.643em;
}
h3 {
font-size: 1.500em;
}
h4 {
font-size: 1.357em;
}
h5 {
font-size: 1.214em;
}
h6 {
font-size: 1.071em;
}
/* vertical centered image with flex */
.vertical-centered-image {
height: 100px;
width: 100%;
display: flex;
overflow: hidden;
align-items: center;
flex-direction: row;
justify-content: center;
}
.vertical-centered-image img {
width: 100%;
height: auto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment