项目作者: ederssouza

项目描述 :
Sass Helpers
高级语言: CSS
项目地址: git://github.com/ederssouza/sass-helpers.git
创建时间: 2017-06-17T16:59:25Z
项目社区:https://github.com/ederssouza/sass-helpers

开源协议:

下载


Sass Helpers

npm version

Functions, mixins and placeholders for speed up your development process.

Installation

  1. npm install @ederssouza/sass-helpers --save-dev

How to use

Import the global index.scss file in your project.

  1. @import '~@ederssouza/sass-helpers';

Mixins

See mixins.scss.

CSS3 animation

scss

  1. .icon {
  2. width: 100px;
  3. height: 100px;
  4. background-color: red;
  5. @include animation(changeBg 4s);
  6. }
  7. @include keyframes(changeBg) {
  8. from {background-color: red;}
  9. to {background-color: yellow;}
  10. }

css compiled

  1. .icon {
  2. width: 100px;
  3. height: 100px;
  4. background-color: red;
  5. -webkit-animation: changeBg 4s;
  6. -moz-animation: changeBg 4s;
  7. animation: changeBg 4s;
  8. }
  9. @-webkit-keyframes changeBg {
  10. from {
  11. background-color: red;
  12. }
  13. to {
  14. background-color: yellow;
  15. }
  16. }
  17. @-moz-keyframes changeBg {
  18. from {
  19. background-color: red;
  20. }
  21. to {
  22. background-color: yellow;
  23. }
  24. }
  25. @keyframes changeBg {
  26. from {
  27. background-color: red;
  28. }
  29. to {
  30. background-color: yellow;
  31. }
  32. }

CSS3 background-size

scss

  1. .container {
  2. @include background-size(cover);
  3. }

css compiled

  1. .container {
  2. -webkit-background-size: cover;
  3. -moz-background-size: cover;
  4. -o-background-size: cover;
  5. background-size: cover;
  6. }

CSS3 border-radius

scss

  1. .container {
  2. @include border-radius(4px);
  3. }

css compiled

  1. .container {
  2. -webkit-border-radius: 4px;
  3. -moz-border-radius: 4px;
  4. border-radius: 4px;
  5. }

CSS3 box-shadow

scss

  1. .container {
  2. @include box-shadow(1px 1px 2px rgba(#000, .8));
  3. }

css compiled

  1. .container {
  2. -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
  3. -moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
  4. box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
  5. }

CSS3 @font-face

scss

  1. $fonts-dir: '../fonts';
  2. @include font-face('Roboto', 'roboto', 'regular');

css compiled

  1. @font-face {
  2. font-family: "Roboto";
  3. src: url("../fonts/regular/roboto.eot");
  4. src: url("../fonts/regular/roboto.eot?#iefix") format("embedded-opentype"), url("../fonts/regular/roboto.woff") format("woff"), url("../fonts/regular/roboto.ttf") format("truetype"), url("../fonts/regular/roboto.svg#Roboto") format("svg");
  5. }

CSS3 linear-gradient

scss

  1. .container {
  2. @include linear-gradient(red, orange);
  3. }

css compiled

  1. .container {
  2. background: orange;
  3. background: -moz-linear-gradient(top, red 0%, orange 100%);
  4. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, red), color-stop(100%, orange));
  5. background: -webkit-linear-gradient(top, red 0%, orange 100%);
  6. background: -o-linear-gradient(top, red 0%, orange 100%);
  7. background: linear-gradient(to bottom, red 0%, orange 100%);
  8. }

opacity

scss

  1. .container {
  2. @include opacity(.5);
  3. }

css compiled

  1. .container {
  2. opacity: 0.5;
  3. filter: alpha(opacity=50);
  4. }

CSS3 placeholder input

scss

  1. input, textarea {
  2. @include placeholder {
  3. font-style:italic;
  4. }
  5. }

css compiled

  1. input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
  2. font-style: italic;
  3. }
  4. input::-moz-placeholder, textarea::-moz-placeholder {
  5. font-style: italic;
  6. }
  7. input:-moz-placeholder, textarea:-moz-placeholder {
  8. font-style: italic;
  9. }
  10. input:-ms-input-placeholder, textarea:-ms-input-placeholder {
  11. font-style: italic;
  12. }

tab-size

scss

  1. pre {
  2. @include tab-size(2);
  3. }

css compiled

  1. pre {
  2. -webkit-tab-size: 2;
  3. -moz-tab-size: 2;
  4. -o-tab-size: 2;
  5. tab-size: 2;
  6. }

CSS3 transform

scss

  1. .icon {
  2. @include transform(scale(1.5));
  3. }

css compiled

  1. .icon {
  2. -webkit-transform: scale(1.5);
  3. -moz-transform: scale(1.5);
  4. -ms-transform: scale(1.5);
  5. transform: scale(1.5);
  6. }

CSS3 transition

scss

  1. button {
  2. background-color: #fff;
  3. @include transition(background-color .26s);
  4. &:hover {
  5. background-color: #333;
  6. }
  7. }

css compiled

  1. button {
  2. background-color: #fff;
  3. -webkit-transition: background-color 0.26s;
  4. -moz-transition: background-color 0.26s;
  5. -o-transition: background-color 0.26s;
  6. transition: background-color 0.26s;
  7. }
  8. button:hover {
  9. background-color: #333;
  10. }

Helpers

center-vertical

scss

  1. .icon {
  2. height: 100px;
  3. width: 100px;
  4. @include center-vertical;
  5. }

css compiled

  1. .icon {
  2. height: 100px;
  3. width: 100px;
  4. left: 50%;
  5. position: absolute;
  6. top: 50%;
  7. -webkit-transform: translate(-50%, -50%);
  8. -moz-transform: translate(-50%, -50%);
  9. -ms-transform: translate(-50%, -50%);
  10. transform: translate(-50%, -50%);
  11. }

sprite

scss

  1. $img-dir: '../img';
  2. .icon {
  3. @include sprite('sprite-icon.png', '0 50px', 50px, 50px);
  4. }

css compiled

  1. .icon {
  2. background-image: url("../img/sprite-icon.png");
  3. background-position: "0 50px";
  4. height: 50px;
  5. width: 50px;
  6. }

Functions

See functions.scss.

Convert px to em

scss

  1. $browser-context: 16;
  2. .container {
  3. font-size: em(14)
  4. }

css compiled

  1. .container {
  2. font-size: 0.875em;
  3. }

Placeholders

See placeholders.scss.

center-block

scss

  1. .container {
  2. @extend %center-block;
  3. }

css compiled

  1. .container {
  2. display: block;
  3. margin-left: auto;
  4. margin-right: auto;
  5. }

clearfix

scss

  1. .container {
  2. @extend %clearfix;
  3. }

css compiled

  1. .container:before,
  2. .container:after {
  3. clear: both;
  4. content: "";
  5. display: block;
  6. }

License

MIT License © Eder Sampaio