mixins.less 20.93 KiB
// Mixins.less
// Snippets of reusable CSS to develop faster and keep code readable
// -----------------------------------------------------------------
// UTILITY MIXINS
// --------------------------------------------------
// Clearfix
// --------
// For clearing floats like a boss h5bp.com/q
.clearfix {
  *zoom: 1;
  &:before,
  &:after {
    display: table;
    content: "";
  &:after {
    clear: both;
// Webkit-style focus
// ------------------
.tab-focus() {
  // Default
  outline: thin dotted #333;
  // Webkit
  outline: 5px auto -webkit-focus-ring-color;
  outline-offset: -2px;
// Center-align a block level element
// ----------------------------------
.center-block() {
  display: block;
  margin-left: auto;
  margin-right: auto;
// IE7 inline-block
// ----------------
.ie7-inline-block() {
  *display: inline; /* IE7 inline-block hack */
  *zoom: 1;
// IE7 likes to collapse whitespace on either side of the inline-block elements.
// Ems because we're attempting to match the width of a space character. Left
// version is for form buttons, which typically come after other elements, and
// right version is for icons, which come before. Applying both is ok, but it will
// mean that space between those elements will be .6em (~2 space characters) in IE7,
// instead of the 1 space in other browsers.
.ie7-restore-left-whitespace() {
  *margin-left: .3em;
  &:first-child {
    *margin-left: 0;
.ie7-restore-right-whitespace() {
  *margin-right: .3em;
  &:last-child {
    *margin-left: 0;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
// Sizing shortcuts // ------------------------- .size(@height, @width) { width: @width; height: @height; } .square(@size) { .size(@size, @size); } // Placeholder text // ------------------------- .placeholder(@color: @placeholderText) { &:-moz-placeholder { color: @color; } &:-ms-input-placeholder { color: @color; } &::-webkit-input-placeholder { color: @color; } } // Text overflow // ------------------------- // Requires inline-block or block for proper styling .text-overflow() { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } // CSS image replacement // ------------------------- // Source: https://github.com/h5bp/html5-boilerplate/commit/aa0396eae757 .hide-text { font: 0/0 a; color: transparent; text-shadow: none; background-color: transparent; border: 0; } // FONTS // -------------------------------------------------- #font { #family { .serif() { font-family: @serifFontFamily; } .sans-serif() { font-family: @sansFontFamily; } .monospace() { font-family: @monoFontFamily; } } .shorthand(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) { font-size: @size; font-weight: @weight; line-height: @lineHeight; } .serif(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) { #font > #family > .serif; #font > .shorthand(@size, @weight, @lineHeight); } .sans-serif(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) {
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
#font > #family > .sans-serif; #font > .shorthand(@size, @weight, @lineHeight); } .monospace(@size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight) { #font > #family > .monospace; #font > .shorthand(@size, @weight, @lineHeight); } } // FORMS // -------------------------------------------------- // Block level inputs .input-block-level { display: block; width: 100%; min-height: 28px; // Make inputs at least the height of their button counterpart .box-sizing(border-box); // Makes inputs behave like true block-level elements } // Mixin for form field states .formFieldState(@textColor: #555, @borderColor: #ccc, @backgroundColor: #f5f5f5) { // Set the text color > label, .help-block, .help-inline { color: @textColor; } // Style inputs accordingly .checkbox, .radio, input, select, textarea { color: @textColor; border-color: @borderColor; &:focus { border-color: darken(@borderColor, 10%); .box-shadow(0 0 6px lighten(@borderColor, 20%)); } } // Give a small background color for input-prepend/-append .input-prepend .add-on, .input-append .add-on { color: @textColor; background-color: @backgroundColor; border-color: @textColor; } } // CSS3 PROPERTIES // -------------------------------------------------- // Border Radius .border-radius(@radius) { -webkit-border-radius: @radius; -moz-border-radius: @radius; border-radius: @radius; } // Single Corner Border Radius .border-top-left-radius(@radius) { -webkit-border-top-left-radius: @radius; -moz-border-radius-topleft: @radius; border-top-left-radius: @radius; }
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
.border-top-right-radius(@radius) { -webkit-border-top-right-radius: @radius; -moz-border-radius-topright: @radius; border-top-right-radius: @radius; } .border-bottom-right-radius(@radius) { -webkit-border-bottom-right-radius: @radius; -moz-border-radius-bottomright: @radius; border-bottom-right-radius: @radius; } .border-bottom-left-radius(@radius) { -webkit-border-bottom-left-radius: @radius; -moz-border-radius-bottomleft: @radius; border-bottom-left-radius: @radius; } // Single Side Border Radius .border-top-radius(@radius) { .border-top-right-radius(@radius); .border-top-left-radius(@radius); } .border-right-radius(@radius) { .border-top-right-radius(@radius); .border-bottom-right-radius(@radius); } .border-bottom-radius(@radius) { .border-bottom-right-radius(@radius); .border-bottom-left-radius(@radius); } .border-left-radius(@radius) { .border-top-left-radius(@radius); .border-bottom-left-radius(@radius); } // Drop shadows .box-shadow(@shadow) { -webkit-box-shadow: @shadow; -moz-box-shadow: @shadow; box-shadow: @shadow; } // Transitions .transition(@transition) { -webkit-transition: @transition; -moz-transition: @transition; -ms-transition: @transition; -o-transition: @transition; transition: @transition; } // Transformations .rotate(@degrees) { -webkit-transform: rotate(@degrees); -moz-transform: rotate(@degrees); -ms-transform: rotate(@degrees); -o-transform: rotate(@degrees); transform: rotate(@degrees); } .scale(@ratio) { -webkit-transform: scale(@ratio); -moz-transform: scale(@ratio); -ms-transform: scale(@ratio); -o-transform: scale(@ratio); transform: scale(@ratio); } .translate(@x, @y) { -webkit-transform: translate(@x, @y); -moz-transform: translate(@x, @y); -ms-transform: translate(@x, @y); -o-transform: translate(@x, @y);