Percentage
This mixin translates a value to a percentage value. Useful to keep code readable.
What you write:
p
width: pct( 280 / 320 )
What you get:
p {
width: 87.5%;
}
By Switch
Lightweight mixin library to help you get the best of Stylus
Chouchenn is a very lightweight mixin library for Stylus. It provides tools to help day-to-day CSS coding:
You can download Chouchenn or clone it from the Github repository. The main files are located in the lib/chouchenn/
folder.
@import 'path/to/chouchenn'
Chouchenn is also available through NPM.
npm install chouchenn
.Example:
var chouchenn = require('chouchenn');
module.exports = function() {
return {
dev:{
files: {
src: 'styles.styl',
dest: 'styles.css'
},
options: {
'use': [ chouchenn ],
'import': ['chouchenn']
}
}
};
};
This mixin translates a value to a percentage value. Useful to keep code readable.
What you write:
p
width: pct( 280 / 320 )
What you get:
p {
width: 87.5%;
}
Assists with value calculations. Furthermore, the code is also more maintainable and readable.
The $rounding
global variable can be used to adjust rounding decimals as needed. Defaults to 3 decimals.
What you write:
$rounding = 3
div
padding: rnd( 7em / 9 ) rnd( 34em / 9 )
What you get:
div {
padding: 0.778em 3.778em;
}
Outputs a micro clearfix to clear your floats.
What you write:
div
clearfix()
What you get:
div:after {
clear: both;
content: "";
display: table;
}
Provides a "ghost" reference element to vertically align all sibling elements.
Note: all sibling elements must have their vertical-align
property set.
What you write:
div
&:before
valign()
What you get:
div:before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
width: 0;
}
Draws diamond-shaped block with CSS (it’s trendy these days). It takes up to five parameters, the first two being mandatory:
What you write:
div
//diamond( size, color, [translateX], [translateY], [transformOrigin] ), for exemple :
diamond( 40px, #dddddd, x: 20px, origin: 100% 100% )
What you get:
div {
background-color: #ddd;
height: 28.284271247461902px;
transform:translateX(20px) rotate(45deg);
transform-origin: 100% 100%;
width: 28.284271247461902px;
}
Example:
Visually hides content. You can use it for image replacement. The benefits of this mixin are:
left:-9999px;
technique) and no weird outline either.Chouchenn also provides a reverse mixin called hide-reset()
to cancel the hiding.
What you write:
h1 span
hide()
What you get:
h1 span {
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
Cancels out the effects of the hide()
mixin.
What you write:
h1 span
hide-reset()
What you get:
h1 span {
clip: auto;
height: auto;
margin: 0;
overflow: visible;
position: static;
width: auto;
}
Generates CSS triangles.
Available direction values: up
, down
, left
, right
, up-left
, up-right
, down-left
and down-right
.
What you write:
span.triangle
triangle( 25px, #808080, up-right )
What you get:
div {
border-left: 25px solid transparent;
border-top: 25px solid #808080;
height: 0;
width: 0;
}
Example:
up
down
left
right
up-left
up-right
down-left
down-right
Defines variables to extend the timing functions initially provided by CSS (based upon jQuery UI timing functions).
Chouchenn provides variants for ease-in
, ease-out
and ease-in-out
to use in your stylesheets:
What you write:
div
transition: width 1.2s ease-in-out-quart
What you get:
div {
transition: width 1.2s cubic-bezier(0.77, 0, 0.175, 1);
}
All available timing functions:
Easy and shorter way to import your different custom fonts. Please refer to the Settings section to understand how to change the font types and their order.
What you write:
$url ='/fonts/Source_Sans_Pro/'
$name ='SourceSansPro-Regular'
fontface( SourceSansPro, '/fonts/Source_Sans_Pro/SourceSansPro-Regular' )
fontface( SourceSansPro, $url + $name )
fontface( SourceSansPro, '/fonts/Source_Sans_Pro/SourceSansPro-Bold', bold )
fontface( SourceSansPro, '/fonts/Source_Sans_Pro/SourceSansPro-Italic', normal, italic )
What you get:
@font-face{
font-family: SourceSansPro;
font-style: normal;
font-weight: normal;
src: url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.eot");
src: url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.eot?#iefix") format("embedded-opentype"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.woff") format("woff"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.ttf") format("truetype"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.svg#SourceSansPro") format("svg");
}
@font-face{
font-family: SourceSansPro;
font-style: normal;
font-weight: normal;
src: url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.eot");
src: url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.eot?#iefix") format("embedded-opentype"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.woff") format("woff"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.ttf") format("truetype"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Regular.svg#SourceSansPro") format("svg");
}
@font-face{
font-family: SourceSansPro;
font-style: normal;
font-weight: normal;
src: url("/fonts/Source_Sans_Pro/SourceSansPro-Bold.eot");
src: url("/fonts/Source_Sans_Pro/SourceSansPro-Bold.eot?#iefix") format("embedded-opentype"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Bold.woff") format("woff"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Bold.ttf") format("truetype"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Bold.svg#SourceSansPro") format("svg");
}
@font-face{
font-family: SourceSansPro;
font-style: normal;
font-weight: normal;
src: url("/fonts/Source_Sans_Pro/SourceSansPro-Italic.eot");
src: url("/fonts/Source_Sans_Pro/SourceSansPro-Italic.eot?#iefix") format("embedded-opentype"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Italic.woff") format("woff"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Italic.ttf") format("truetype"),
url("/fonts/Source_Sans_Pro/SourceSansPro-Italic.svg#SourceSansPro") format("svg");
}
Does the line-height
maths for you. The mixins takes the context font-size
value as a unique parameter.
This mixin adds the $lh-base
variable value to the font-size
provided, divides the sum by the font-size value and returns the result of the calculation. $lh-base
defaults to 4.
What you write:
// let's assume the font-size is 28px
p
line-height: lh( 28 )
What you get:
p {
line-height: 1.143;
}
Returns the result of the calculation in em
s.
What you write:
p
font-size: em( 12 / 16 )
What you get:
p {
font-size: 0.75em;
}
Returns the value passed as a parameter in rem
. Uses the $rem-base
variable to do the maths (in case you redefine the root font-size
of the page). This variable defaults to 16px.
What you write:
p
font-size: rem( 10 )
What you get:
p {
font-size: 0.625rem;
}
In addition to the mixins, Chouchenn provides several configuration settings to give you more control over the way mixins behave.
$font-type
: sets the font-face formats and their order. Used in the font-face mixin.$rounding
: adjusts the rounding mixin decimal numbers.$lh-base
: sets the value added to the font-size of the line-height mixin.$rem-base
: sets the base font-size reference for the rem-size mixin.Global variables default values:
$font-type ?= eot woff ttf svg
$rounding ?= 3
$lh-base ?= 4
$rem-base ?= 16
Chouchenn is a tool library. It is not (and never will be) intended to support prefixes or special syntaxes, etc. There are better tools for this (like autoprefixer) and we strongly encourage you to use them in addition of Chouchenn.
Chouchenn is free software and licenced under the BSD licence. For more details, please refer to the LICENCE file.