hacks-guide-minimal-mistake.../assets/less/mixins.less

296 lines
9 KiB
Text
Raw Normal View History

2013-09-07 14:44:10 +02:00
// UTILITY MIXINS
// --------------------------------------------------
// Clearfix
// --------------------
// For clearing floats like a boss h5bp.com/q
.clearfix {
*zoom: 1;
&:before,
&:after {
display: table;
content: "";
// Fixes Opera/contenteditable bug:
// http://nicolasgallagher.com/micro-clearfix-hack/#comment-36952
line-height: 0;
}
&:after {
clear: both;
}
}
2013-05-24 16:25:31 +02:00
2013-09-07 14:44:10 +02:00
// Webkit-style focus
// --------------------
.tab-focus() {
// Default
outline: thin dotted #333;
// Webkit
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
2013-05-24 16:25:31 +02:00
2013-09-07 14:44:10 +02:00
// Center-align a block level element
// ----------------------------------
.center-block() {
display: block;
margin-left: auto;
margin-right: auto;
}
2013-05-24 16:25:31 +02:00
2013-09-07 14:44:10 +02:00
// TYPOGRAPHY
// --------------------------------------------------
// Full-fat vertical rhythm
// ------------------------
.font-size(@size) {
font-size: 0px + @size;
font-size: 0rem + @size / @doc-font-size;
line-height: 0 + round(@doc-line-height / @size*10000) / 10000;
margin-bottom: 0px + @doc-line-height;
margin-bottom: 0rem + (@doc-line-height / @doc-font-size);
}
2013-05-24 16:25:31 +02:00
2013-09-07 14:44:10 +02:00
// Just the REMs
// -------------
.font-rem(@size) {
font-size: 0px + @size;
font-size: 0rem + @size / @doc-font-size;
}
// Just font-size and line-height
// ------------------------------
.font(@size) {
font-size: 0px + @size;
font-size: 0rem + @size / @doc-font-size;
line-height: 0 + round(@doc-line-height / @size*10000) / 10000;
}
2013-05-24 16:25:31 +02:00
.text-overflow() {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap; }
2013-09-07 15:42:28 +02:00
@indent-var: 0rem + (@doc-line-height / @doc-font-size);
2013-09-07 14:44:10 +02:00
// GRADIENTS
// --------------------------------------------------
2013-05-24 16:25:31 +02:00
.horizontal(@startColor : @white, @endColor : @lightergrey) {
background-color: @endColor;
background-image : -webkit-gradient(linear, 0 0, 100% 0, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+
2013-09-07 14:44:10 +02:00
background-image : -webkit-linear-gradient(left, @startColor, @endColor); // Safari 5.1+, Chrome 10+
background-image : -moz-linear-gradient(left, @startColor, @endColor); // FF 3.6+
background-image : -ms-linear-gradient(left, @startColor, @endColor); // IE10
background-image : -o-linear-gradient(left, @startColor, @endColor); // Opera 11.10
background-image : linear-gradient(left, @startColor, @endColor); // W3C
2013-05-24 16:25:31 +02:00
background-repeat : repeat-x; }
.vertical(@startColor : @white, @endColor: @lightergrey) {
background-image : -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+
2013-09-07 14:44:10 +02:00
background-image : -webkit-linear-gradient(top, @startColor, @endColor); // Safari 5.1+, Chrome 10+
2013-05-24 16:25:31 +02:00
background-color : @endColor;
2013-09-07 14:44:10 +02:00
background-image : -moz-linear-gradient(top, @startColor, @endColor); // FF 3.6+
background-image : -ms-linear-gradient(top, @startColor, @endColor); // IE10
background-image : -o-linear-gradient(top, @startColor, @endColor); // Opera 11.10
background-image : linear-gradient(top, @startColor, @endColor); // W3C
2013-05-24 16:25:31 +02:00
background-repeat : repeat-x; }
.directional(@startColor : @white, @endColor : @lightergrey, @deg : 45deg) {
background-color : @endColor;
2013-09-07 14:44:10 +02:00
background-image : -moz-linear-gradient(@deg, @startColor, @endColor); // FF 3.6+
background-image : -ms-linear-gradient(@deg, @startColor, @endColor); // IE10
background-image : -webkit-linear-gradient(@deg, @startColor, @endColor); // Safari 5.1+, Chrome 10+
background-image : -o-linear-gradient(@deg, @startColor, @endColor); // Opera 11.10
background-image : linear-gradient(@deg, @startColor, @endColor); // W3C
2013-05-24 16:25:31 +02:00
background-repeat : repeat-x; }
2013-09-07 14:44:10 +02:00
// .bordered(COLOR, COLOR, COLOR, COLOR);
2013-05-24 16:25:31 +02:00
.bordered(@top-color: #eee, @right-color: #eee, @bottom-color: #eee, @left-color: #eee) {
border-top : solid 1px @top-color;
border-left : solid 1px @left-color;
border-right : solid 1px @right-color;
border-bottom : solid 1px @bottom-color; }
2013-09-07 14:44:10 +02:00
// ROUND CORNERS
// --------------------------------------------------
// .rounded(VALUE);
2013-05-24 16:25:31 +02:00
.rounded(@radius:4px) {
-webkit-border-radius : @radius;
-moz-border-radius : @radius;
border-radius : @radius; }
2013-09-07 14:44:10 +02:00
// .border-radius(VALUE,VALUE,VALUE,VALUE);
2013-05-24 16:25:31 +02:00
.border-radius(@topright: 0, @bottomright: 0, @bottomleft: 0, @topleft: 0) {
-webkit-border-top-right-radius : @topright;
-webkit-border-bottom-right-radius : @bottomright;
-webkit-border-bottom-left-radius : @bottomleft;
-webkit-border-top-left-radius : @topleft;
-moz-border-radius-topright : @topright;
-moz-border-radius-bottomright : @bottomright;
-moz-border-radius-bottomleft : @bottomleft;
-moz-border-radius-topleft : @topleft;
border-top-right-radius : @topright;
border-bottom-right-radius : @bottomright;
border-bottom-left-radius : @bottomleft;
border-top-left-radius : @topleft;
-webkit-background-clip : padding-box;
-moz-background-clip : padding;
background-clip : padding-box; }
2013-09-07 14:44:10 +02:00
// .box-shadow(HORIZONTAL VERTICAL BLUR COLOR))
2013-05-24 16:25:31 +02:00
.box-shadow(@shadow: 0 1px 3px rgba(0,0,0,.25)) {
-webkit-box-shadow : @shadow;
-moz-box-shadow : @shadow;
box-shadow : @shadow; }
2013-09-07 14:44:10 +02:00
// .drop-shadow(HORIZONTAL, VERTICAL, BLUR, ALPHA);
2013-05-24 16:25:31 +02:00
.drop-shadow(@x-axis: 0, @y-axis: 1px, @blur: 2px, @alpha: 0.1) {
-webkit-box-shadow : @x-axis @y-axis @blur rgba(0, 0, 0, @alpha);
-moz-box-shadow : @x-axis @y-axis @blur rgba(0, 0, 0, @alpha);
box-shadow : @x-axis @y-axis @blur rgba(0, 0, 0, @alpha); }
2013-09-07 14:44:10 +02:00
// .text-shadow();
2013-05-24 16:25:31 +02:00
.text-shadow(@shadow: 0 2px 3px rgba(0,0,0,.25)) {
text-shadow : @shadow; }
2013-09-07 14:44:10 +02:00
// .opacity(VALUE);
2013-05-24 16:25:31 +02:00
.opacity(@opacity : .5) {
-webkit-opacity : @opacity;
-moz-opacity : @opacity;
opacity : @opacity; }
2013-09-07 14:44:10 +02:00
// TRANSFORMATIONS
// --------------------------------------------------
// .rotate(VALUEdeg);
2013-05-24 16:25:31 +02:00
.rotate(@deg) {
-webkit-transform : rotate(@deg);
-moz-transform : rotate(@deg);
-ms-transform : rotate(@deg);
-o-transform : rotate(@deg);
transform : rotate(@deg); }
2013-09-07 14:44:10 +02:00
// .scale(VALUE);
2013-05-24 16:25:31 +02:00
.scale(@ratio) {
-webkit-transform : scale(@ratio);
-moz-transform : scale(@ratio);
-ms-transform : scale(@ratio);
-o-transform : scale(@ratio);
transform : scale(@ratio); }
2013-09-07 14:44:10 +02:00
// .skew(VALUE, VALUE);
2013-05-24 16:25:31 +02:00
.skew(@x: 0, @y: 0) {
-webkit-transform : skew(@x, @y);
-moz-transform : skew(@x, @y);
-ms-transform : skew(@x, @y);
-o-transform : skew(@x, @y);
transform : skew(@x, @y); }
2013-09-07 14:44:10 +02:00
// .transition(PROPERTY DURATION DELAY(OPTIONAL) TIMING-FINCTION);
2013-05-24 16:25:31 +02:00
.transition(@transition) {
-webkit-transition : @transition;
-moz-transition : @transition;
-ms-transition : @transition;
-o-transition : @transition;
transition : @transition; }
2013-09-07 14:44:10 +02:00
// .translate(VALUE, VALUE)
2013-05-24 16:25:31 +02:00
.translate(@x: 0, @y: 0) {
-webkit-transform : translate(@x, @y);
-moz-transform : translate(@x, @y);
-ms-transform : translate(@x, @y);
-o-transform : translate(@x, @y);
transform : translate(@x, @y); }
.translate3d(@x: 0, @y: 0, @z: 0) {
-webkit-transform : translate(@x, @y, @z);
-moz-transform : translate(@x, @y, @z);
-ms-transform : translate(@x, @y, @z);
-o-transform : translate(@x, @y, @z);
transform : translate(@x, @y, @z); }
2013-09-07 14:44:10 +02:00
.animation(@name, @duration: 300ms, @delay: 0, @ease: ease) {
-webkit-animation: @name @duration @delay @ease;
-moz-animation: @name @duration @delay @ease;
-ms-animation: @name @duration @delay @ease;
}
// BACKGROUND
// --------------------------------------------------
// .background-alpha(VALUE VALUE);
2013-05-24 16:25:31 +02:00
.background-alpha(@color: @white, @alpha: 1) {
background-color : hsla(hue(@color), saturation(@color), lightness(@color), @alpha); }
2013-09-07 14:44:10 +02:00
// .background-size(VALUE VALUE);
2013-05-24 16:25:31 +02:00
.background-size(@size){
-webkit-background-size : @size;
-moz-background-size : @size;
-o-background-size : @size;
background-size : @size; }
2013-09-07 14:44:10 +02:00
// .background-clip(VALUE); (border-box, padding-box, content-box)
2013-05-24 16:25:31 +02:00
.background-clip(@clip) {
-webkit-background-clip : @clip;
-moz-background-clip : @clip;
background-clip : @clip; }
2013-09-07 14:44:10 +02:00
// .box-sizing(VALUE); (border-box, padding-box, content-box)
2013-05-24 16:25:31 +02:00
.box-sizing(@boxsize: border-box) {
-webkit-box-sizing : @boxsize;
-moz-box-sizing : @boxsize;
-ms-box-sizing : @boxsize;
box-sizing : @boxsize; }
2013-09-07 14:44:10 +02:00
// For image replacement
2013-05-24 16:25:31 +02:00
.hide-text() {
text-indent : 100%;
white-space : nowrap;
overflow : hidden; }
2013-09-07 14:44:10 +02:00
// Hide from visual and speaking browsers
2013-05-24 16:25:31 +02:00
.hidden() {
display : none !important;
visibility : hidden; }
.hidden {
display: none;
visibility: hidden;
}
2013-09-07 14:44:10 +02:00
// Hide but maintain layout
2013-05-24 16:25:31 +02:00
.invisible() {
visibility : hidden; }
2013-09-07 14:44:10 +02:00
// .resize(VALUE) (none, both, horizontal, vertical, inherit)
2013-05-24 16:25:31 +02:00
.resize(@direction: both) {
resize : @direction;
overflow : auto; }
2013-09-07 14:44:10 +02:00
// .userselect(VALUE) (all, element, none, text)
2013-05-24 16:25:31 +02:00
.user-select(@select) {
-webkit-user-select : @select;
-moz-user-select : @select;
-o-user-select : @select;
user-select : @select; }
2013-09-07 14:44:10 +02:00
// Hidden but available to speaking browsers
2013-05-24 16:25:31 +02:00
.visuallyhidden() {
overflow : hidden;
position : absolute;
clip : rect(0 0 0 0);
height : 1px;
width : 1px;
margin : -1px;
padding : 0;
border : 0; }
2013-09-07 14:44:10 +02:00
// Make visuallyhidden focusable with a keyboard
2013-05-24 16:25:31 +02:00
.visuallyhidden.focusable:active,
.visuallyhidden.focusable:focus {
position : static;
clip : auto;
height : auto;
width : auto;
margin : 0;
2013-09-07 14:44:10 +02:00
overflow: visible; }