Ifkit, or Interface Foundation Kit, is a set of convenience mixins for your everyday SASS needs. We've been making the same classes for almost every project we do, so we're moving to standardize that set of controls.
Ifkit requires Sass and Compass. Some Ifkit mixins need Sass 3.2+ to function (they're marked as such in this documentation), while most will work with any version of Sass.
Add the Ifkit stylesheets into your project. The recommended usage
is to put ifkit/
into your project's Sass directory
(vendor/assets/stylesheets/
in Rails).
Ifkit aims to be a collection of self-contained building blocks of common interface patterns. It is not a CSS framework like Bootstrap and such.
Some mixins may need Sass 3.2+ (specifically the media queries). This is
to support mixins that can have content blocks (eg, +if-retina { ... }
).
If you arre using Ruby + Bundler, simply update your Gemfile to use a prerelease version:
gem 'sass', '~> 3.2.0.alpha'
Or if you don't use Bundler, install it with gem install sass --pre
.
Easy cross-browser animations. Supported by FF, Webkits, and IE10+ so far. (Reference)
To use, import this group in your stylesheet using @import 'ifkit/animation';
.
Note: this is only useable in Sass 3.2.
@include if-keyframes(drift) { 0% { background-position: 0 0; } 100% { background-position: -1000px 0; } } .images { @include if-animation(drift, 90s, infinite, linear); }
Makes animations. See above for an example.
Defines keyframes for an animation. See above for an example.
Ifkit provides some mixins for buttons.
Take note that all buttons must be laid on top of a parent element that has
position: relative; z-index: 0;
. This is because Ifkit relies on z-index:
-1
for button borders, and elements with negative z-indices will not be
visible if it's not placed a parent that has a z-index
of >= 0
.
<span class='button-1'>Take the tour</span>
<span class='button-2'>Cancel</span>
.button-1 {
@include if-primary-button; }
.button-2 {
@include if-default-button; }
Ifkit comes with a few default button styles.
You may override these styles by re-defining them. These are merely built with the other button mixins below.
<span class='button-red'>Red button</span>
<span class='button-red-flat'>Flat button</span>
.button-red {
@include if-button-color(#d33, 0.5, 1.1, 0.8, 0.8, 0.2); }
.button-red-flat {
@include if-button-color(#d33, 1.0, 1.1, 0.9, 0.8, 0.2); }
You may specify additional parameters. All parameters except $color
are
optional.
1.0
makes the button flat, 0
makes the button dark.1.0
makes the border have the same
color as the button, < 1
makes it darker, > 1
makes it lighter.
none
removes the border.0.0
makes it invisible, 1.0
makes it
completely white.<span class='button-pill'>Pill button</span>
.button-pill {
@include if-button-color(#eee, 0.9);
@include if-button-height(32px, 0 20px);
@include if-button-radius(16px);
color: #333;
font-weight: bold;
font-size: 11pt;
text-shadow: 1px 1px 0 rgba(white, 0.5); }
Mixins to enhance if-button-color
.
It is encouraged for you to make your own mixins using if-button-color
and these, just like the example below.
To use, import this group in your stylesheet using @import 'ifkit/form';
.
Alias for the selector that targets all textboxes. Equivalent to
input[type=text], input[type=password],
input[type=email], input[type=search], input:not([type])
.
<input class='textbox' type='text' value='Normal text box' />
and
<input class='textbox' disabled='disabled' type='text' value='Disabled text box' />
#{$if-textboxes} {
&.textbox {
@include if-textbox; } }
Textbox. Includes styles for disabled, hover, focus, et al. Works great
for <input>
and <textarea>
alike.
<select class='my-select'>
<option>Choose your weapon...</option>
</select>
and
<select class='my-select' disabled='disabled'>
<option>Disabled</option>
</select>
.my-select {
@include if-select; }
<form class='my-form'>
<!-- Basic fields are simply label+input pairs. -->
<div class='field'>
<label>Username:</label>
<input type='text' />
</div>
<!-- For most cases, you will want to wrap -->
<!-- the controls inside `.controls`. -->
<div class='field'>
<label>Email:</label>
<div class='controls'>
<input type='text' />
<span class='help'>We will never sell your email address.</span>
</div>
</div>
<!-- Radio button fields have class='radio' -->
<!-- to reduce the line height. -->
<div class='field'>
<label>Gender:</label>
<div class='controls'>
<div class='control'>
<input type='radio' />
<label>Male</label>
</div>
<div class='control'>
<input type='radio' />
<label>Female</label>
</div>
</div>
</div>
<!-- Horizontal layouts have class='horizontal'. -->
<div class='field'>
<label>Full name:</label>
<div class='controls horizontal'>
<div class='control'>
<input type='text' />
<label>First name</label>
</div>
<div class='control'>
<input type='text' />
<label>Last name</label>
</div>
</div>
</div>
</form>
form.my-form {
@include if-form-layout($field: '.field');
fieldset {
border: 0; }
#{$if-textboxes}, textarea {
@include if-textbox; } }
Gives fields in a side-by-side layout. Does not give any visual style to any
of the elements, it simply gives them layout. This is often used on fieldset
or form
. You may specify some selectors:
.field
..controls
..control
.Common settings:
fieldset
for $field.>*
for $field as well.You can add .horizontal
(see "Full name" in the example) to the field
control group to lay out its controls horizontally.
You can also add .radio
or .checkbox
to .field
for a reduced
line-height (see "Gender:").
All parameters are optional.
<form class='my-form-2'>
<div class='field'>
<label>Address:</label>
<div class='controls horizontal'>
<div class='control p20'>
<input type='text' />
<label>Number</label>
</div>
<div class='control p40'>
<input type='text' />
<label>Building</label>
</div>
<div class='control p40'>
<input type='text' />
<label>Complex</label>
</div>
<div class='control p50'>
<input type='text' />
<label>Street 1</label>
</div>
<div class='control p50'>
<input type='text' />
<label>Street 2</label>
</div>
</div>
</div>
<div class='field'>
<label>Full name:</label>
<input class='p100' type='text' />
</div>
<div class='field'>
<label>Full name:</label>
<input class='p100' type='text' />
</div>
</form>
form.my-form-2 {
@include if-form-layout;
@include if-form-widths;
#{$if-textboxes} {
@include if-textbox; } }
Adds widths classes to controls. This lets you add .p20
classes to each
individual control, where 20 is the width in percent.
Use this in conjunction with if-form-layout
, like in the example.
Form resets.
To use, import this group in your stylesheet using @import 'ifkit/form_reset';
.
A supplement to CSS resets to ensure consistency of form elements as well.
Simply add @include if-form-normalize;
to ensure consistency between browsers.
A supplement to CSS resets to ensure consistency of form elements, as well as reset the appearances of buttons and other elements.
Implies if-form-normalize
.
Media query helpers. Requires SASS 3.2. Don't use with 3.1 or lower.
Mixins for presets of width ranges. Phone-portrait is < 320px, Phone is <480px, Tablet is 768px to 1024px.
Mobile is 1024px which accounts for typical maximized desktop screens.
Examples:
body { @include if-mobile { #top, #footer { display: none; } } @include if-phone { #menu { height: 20px; } }
Screen widths. You may specify min and max as either a px
number, or none
.
@include if-screen-width(480px, none) { ... } /* 480px and up */ @include if-screen-width($max: 1024px) { ... } /* 1024px and below */ @include if-screen-width(none, 1024px) { ... } /* 1024px and below */
Checks for retina support.
Mixins for portait or landscape mode for mobile devices.
Mixins used for making mobile web applications.
Disables common tap stuff for iOS webapps such as tap outlines, image save panel, and so on.
# Use it at the top level @include if-mobile-reset;
References: - http://wiki.phonegap.com/w/page/16494795/iPhone%3A%20Prevent%20callout,%20link%20selection,%20text%20auto-resize - http://www.bitsandpix.com/entry/ios-webkit-uiwebview-remove-tapclick-highlightborder-with-css/
Mixin for normalizing content appearances. Great if you use a reset.
To use, import this group in your stylesheet using @import 'ifkit/normalize';
.
Dolorem sapiente animi et at. Quaerat quia ipsam ut ipsum non. Vel dolores voluptas similique.
Aut ipsum vel fugiat id laborum adipisci ullam et. Recusandae nihil qui quod eum laboriosam. Laboriosam officia sunt sit architecto.
<div class='content-area'>
<h2>Hello</h2>
<p>Dolorem sapiente animi et at. Quaerat quia ipsam ut ipsum non. Vel dolores voluptas similique.</p>
<p>Aut ipsum vel fugiat id laborum adipisci ullam et. Recusandae nihil qui quod eum laboriosam. Laboriosam officia sunt sit architecto.</p>
<ul>
<li>Lorem</li>
<li>Hello</li>
<li>Hello</li>
<li>Hello</li>
</ul>
</div>
.content-area {
@include if-content; }
Normalizes typography for content areas.
You may specify additional parameters.
20px
.25px
.true
, ensures that the top/bottom blocks don't have margins. Defaults
to true
.Adjusts vertical margins between blocks.
Dolorem sapiente animi et at. Quaerat quia ipsam ut ipsum non. Vel dolores voluptas similique.
Aut ipsum vel fugiat id laborum adipisci ullam et. Recusandae nihil qui quod eum laboriosam. Laboriosam officia sunt sit architecto.
<div class='content-area'>
<h2>Hello</h2>
<p>Dolorem sapiente animi et at. Quaerat quia ipsam ut ipsum non. Vel dolores voluptas similique.</p>
<p>Aut ipsum vel fugiat id laborum adipisci ullam et. Recusandae nihil qui quod eum laboriosam. Laboriosam officia sunt sit architecto.</p>
</div>
.contents {
@include if-vertical-margins(20px); }
Removes top/bottom margins from a content block. Use with if-content
.
Horizontal definition lists.
For tooltips and things that have triangles sticking out of them.
To use, import this group in your stylesheet using @import 'ifkit/notch';
.
Simple notch.
Unlike if-notch, this one only supports color. It can't do shadows or
backgrounds. However, the markup it uses is much simpler, there is no
need for an extra element, and it's possible to use it on a :before
or
:after
pseudo-element.
@include if-simple-notch(left, #fff, 10px)
<span class='inotch top'></span>
<span class='inotch left'></span>
<span class='inotch bottom'></span>
<span class='inotch right'></span>
.inotch.top {
@include if-notch(top, #888); }
.inotch.left {
@include if-notch(left, #888); }
.inotch.bottom {
@include if-notch(bottom, #888); }
.inotch.right {
@include if-notch(right, #888); }
.inotch {
margin: 3px;
float: left;
outline: dotted 1px red; }
Makes a free, notch triangle shape that has display: block
.
<div class='notched'>
<div class='notch'></div>
Hello.
</div>
.notched {
width: 200px;
height: 50px;
background: #888;
color: #ddd;
padding: 10px;
position: relative;
.notch {
@include if-box-notch(top, left, $color: #888) } }
Gives a box a notch. Give it to the notch sub-element of the box.
Note: ensure that the parent box has a position
property, even if it's
just position: relative
.
Macros to help make absolute/relative positioning easier.
To use, import this group in your stylesheet using @import 'ifkit/position';
.
Macros for absolute, relative, and fixed positioning.
.toolbar { @include if-absolute(0, auto, 50px, 50px); } .icon { @include if-relative($top: 0, $left: 50px); }
Helpers for making sprite sheets that are retina-compatible. Requires SASS 3.2. Don't use with 3.1 or lower.
Helper for Retina sprites.
Put your icon sprites in 2 folders: one for 1x assets, and another for 2x
assets. Make sure that the filenames are the same (eg, icon/mail.png
corresponds to icon2x/mail.png
.)
Define 2 sprite maps using the Compass sprite-map
helper for these two paths.
It's recommended to make a mixin for defining your icons.
$icon: sprite-map("icon/*.png"); $icon2x: sprite-map("icon2x/*.png"); @mixin icon($name) { @include if-retina-sprite($name, $icon, $icon2x); } /* Use it like so: */ button.mail { @include icon(mail); }
You can also define a padding by passing a 4th parameter. Be sure that your
sprite maps have enough spacing
to allow for this. This is great for
expanding the hit area for iPhone assets.
/* Note that spacing in the 2x is twice the spacing of the 1x. */ $icon: sprite-map("icon/*.png", $spacing: 20px); $icon2x: sprite-map("icon2x/*.png", $spacing: 40px); @mixin icon($name, $pad: 0) { @include if-retina-sprite($name, $icon, $icon2x, $pad); } /* This gives you a padding of 10px. */ button.mail { @include icon(mail, 10px); }
To use, import this group in your stylesheet using @import 'ifkit/utilities';
.
Works like linear-gradient
, but assumes that it's always vertical and has
a background-color
fallback.
Cross-browser PIE clear fix.
Resets a <ul>
s styles. If either $ul
or $li
are given,
their respective elements will get that as a display property.
<ul class='non-list'>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
ul.non-list {
@include if-non-list;
& {
background: #555;
color: #fff;
padding: 5px; }
>li {
padding: 0 10px; } }
Resets a <ul>
s styles to make it's <li>
s lay out horizontally. Perfect
for horizontal menus.
<div class='centered-list'>
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
div.centered-list {
background: #555;
color: #fff;
padding: 5px;
overflow: hidden;
ul {
@include if-center-list; }
ul>li {
padding: 0 10px; } }
Works like if-horiz-list
, but centers the list items. Perfect for
horizontal menus that are centered. Be sure to overflow: hidden
the
container!
Truncates text using ellipses. Only works in Webkit and Opera.