introduce
A minimalist and lightweight Sass tool library, including Sass mixes, functions, default variables, etc.
If not necessary, do not add entities.
Naming conventions
BEM naming.
Github.com/zhaotoday/w…
Method of use
#The installation
$ npm install --save sass-utilsCopy the code
/* Import */ in the sass file
@import "~sass-utils";
.selector {
/* Call mix */
@include position--relative;
/* Use default variables to set the font */
font-family: $font-family-english;
}
/* Rewrites the function to make it easier to call */
$colors: red yellow;
@function color($index) {
@return _color($colors.$index);
}Copy the code
text–middle
The text is centered vertically.
// sass
.selector {
@include text--middle(100px);
}Copy the code
// css
.selector {
height: 100px;
line-height: 100px;
} Copy the code
Block-level elements are horizontally centered.
// sass
.selector {
@include block--center;
}Copy the code
// css
.selector {
margin-left: auto;
margin-right: auto;
}Copy the code
link–block
Block links.
// sass
.selector {
@include link--block(100px. 200px);
}Copy the code
// css
.selector {
display: block;
text-decoration: none;
width: 100px;
height: 200px;
}Copy the code
Image block.
// sass
.selector {
@include img--block(100px. 200px);
}Copy the code
// css
.selector {
display: block;
width: 100px;
height: 200px;
}Copy the code
_font
Font. Need to be rewritten in business code for easy invocation.
// sass
$fonts: (12px) (13px bold);
@mixin font($index) {
@include _font($fonts.$index);
}
.selector {
@include font(2);
}Copy the code
// css
.selector {
font-size: 13px;
font-weight: bold;
}
[data-dpr="2"] .selector {
font-size: 26px;
}
[data-dpr="3"] .selector {
font-size: 39px;
}Copy the code
BEM block.
// sass
@include b(block) {
// ...
@include e(element) {
// ...
@include m(modifier) {
// ...}}}Copy the code
// css
.block {
// ...
}
.block__element {
// ...
}
.block__element--modifier {
// ...
}Copy the code
e
BEM element.
BEM modifier.
clearfix
Clear the float.
// sass
.selector {
@include clearfix;
}Copy the code
// css
.selector::before..selector::after {
content: "";
display: table;
}
.selector::after {
clear: both;
}Copy the code
Set the margin.
// sass
.selector {
@include margin(100px. 200px. 300px. 400px);
}Copy the code
// css
.selector {
margin-top: 100px;
margin-right: 200px;
margin-bottom: 300px;
margin-left: 400px;
}Copy the code
padding
Sets the padding.
// sass
.selector {
@include padding(100px. 200px.null. 400px);
}Copy the code
// css
.selector {
padding-top: 100px;
padding-right: 200px;
padding-left: 400px;
}Copy the code
Use an ellipsis to replace the rest of the text.
// sass
.selector {
@include text--overflow;
}Copy the code
// css
.selector {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}Copy the code
only-ie8
Only Internet Explorer 8 is available.
// sass
.selector {
@include only-ie8(display.inline);
}Copy the code
// css
.selector {
display: inline\9;
}Copy the code
Relative positioning.
// sass
.selector {
@include position--relative(100px. 200px);
}Copy the code
// css
.selector {
position: relative;
top: 100px;
right: 200px;
}Copy the code
position–absolute
Absolute positioning.
// sass
.selector {
@include position--absolute(100px. 200px);
}Copy the code
// css
.selector {
position: absolute;
top: 100px;
right: 200px;
}Copy the code
Fixed positioning.
// sass
.selector {
@include position--fixed(100px. 200px);
}Copy the code
// css
.selector {
position: fixed;
top: 100px;
right: 200px;
}Copy the code
inline–block
Compatible with IE8 display: inline-block.
// sass
$supports-ie8: true;
.selector {
@include inline--block;
}Copy the code
// css
.selector {
display: inline-block;
display: inline\9;
zoom: 1\9;
}Copy the code
Set the width and height.
// sass
.selector {
@include size(100px. 200px);
}Copy the code
// css
.selector {
width: 100px;
height: 200px;
}Copy the code
Functions
Pixel to REM.
// sass
@function px2rem ($px) {
@return _px2rem($px. 75);
}
.selector {
width: px2rem(750px);
}Copy the code
// css
.selector {
width: 10rem;
}Copy the code
_color
Get the color. Need to be rewritten in business code for easy invocation.
// sass
$colors: yellow red;
@function color($index) {
@return _color($colors.$index);
}
.selector {
color: color(2);
}Copy the code
// css
.selector {
color: red;
}Copy the code
$font-family
Chinese font.
Mobile fonts.
$font-family-english
English font.
BEM Element delimiter.
$separator-modifier
BEM Modifier delimiter.
Whether it is compatible with Internet Explorer 8.