Bourbon & Beef Tasting at Volare, May 1
Getting started with Bourbon
Compass is the most famous Sass mixin library. It provides lots of cross-browser CSS implementations alongside powerful helper features like easy information URI and image sprite creation and more. However, some argue it's a layer of complexity they tin can alive without, particularly if they're just offset with Sass. This is where Bourbon comes in.
Bourbon describes itself as "A simple and lightweight mixin library for Sass". The project's creator, Phil LaPier expands upon this, proverb, "I wanted a unified mixin library to make information technology easier to update vendor prefixes, and to have a elementary starting place for all our new projects, and then I created Bourbon."
Try the Bourbon
In case you're non familiar with the term 'mixin', information technology's a feature when using Sass to produce repetitive CSS lawmaking with ease. An obvious use example is vendor prefixes for experimental CSS backdrop. A mixin saves all the usual laborious repetition. Here is an example from the Bourbon docs:
.linear-gradient { @include linear-gradient(#1e5799, #2989d8); }
That produces this CSS:
.linear-gradient { background-color: #1e5799; background-image: -webkit-gradient(linear, left acme, left lesser, color-terminate(0%, #1e5799), color-end(100%, #2989d8)); background-image: -webkit-linear-slope(#1e5799, #2989d8); background-image: linear-slope(#1e5799, #2989d8); }
Bourbon has generated a full 'vendor stack' of CSS backdrop that will afford the widest possible browser support. In improver, for bonus points, it automatically creates a solid hex-based background colour from the first colour value passed (that value can be changed if needed) for browsers that take no idea what a linear gradient even is.
Such functionality is very much the domain of Compass. So what prompted the creation of Bourbon? "I tried Compass before writing Bourbon, merely I had a poor experience with information technology," explains LaPier. "Compass required a configuration file, the documentation was hard to navigate, and bluntly I struggled to get it working on whatsoever of my projects - it was a huge pain. I wanted something easier to apply and less bloated - something that just worked."
Bourbon has mixins for everything from experimental CSS properties to modular scale and golden ratio helpers. Hopefully your appetite has been whetted enough to take a closer look. Let's get information technology installed and take a few features for a spin.
Installing Bourbon
We're assuming here you'll be setting up a standalone project although, if yous're a Rails user, y'all can bring it into your project using a gem file (jewel 'bourbon') and running bundle install. For anybody else, there are two options: install from the command line or use a GUI tool like LiveReload, Hammer or CodeKit that back up Bourbon 'out of the box'. However, be aware that some of the GUI tools may lag behind the latest releases of Bourbon. For brevity, we're unable to embrace how to use the command line hither. If the thought of using the command line gives you goose bumps, you'd best pay for a GUI tool instead.
To install Bourbon from the command line. Open your control line interface and type the following (Windows users may need to install Crimson first):
gem install bourbon
And printing enter. If y'all're on OS X (or Linux), there'southward a chance you'll need super user rights to install information technology. In which case, type the post-obit and printing enter:
sudo jewel install bourbon
Including Bourbon in a project
If you're a Compass user, including Bourbon in a project may seem a little odd. Without the Compass config.rb file at that place is no easy manner to require additional plugins in the Sass project.
Therefore, information technology'south necessary to include all the Bourbon files in a project manually. Thankfully, there's a single Bourbon command to practice this (be aware that if using a GUI tool you tin can ignore this next step). In the root of your project folder, type the post-obit on the control line and press enter:
bourbon install
This will create a binder called bourbon containing all the Bourbon mixins and files necessary to get working with Bourbon. With that done, add the following line at the elevation of your master style sheet @import 'bourbon/bourbon';. Now we're ready to play with all that Bourbon has to offer. If y'all don't take something lined up to compile the Sass (for example, Grunt or a GUI tool) then run the following command: sass --lookout man sass:css where css is the resultant binder for the generated CSS.
Defining features
Rather than await at the usual suspects (gradients, border-radius, multi-columns and the similar) let'southward look at some of the more unusual things that Bourbon includes.
Easy buttons
Need to create smart looking buttons with minimal endeavour? Bourbon has you covered. Here's how you can make a rounded push button:
.pill-button { @include button(pill, #ff9900);}
The mixin takes two arguments. A manner (unproblematic, shiny or pill) and then a color. The result in this example saves writing 37 lines of 'vanilla' CSS lawmaking!
Like shooting fish in a barrel CSS triangles
Bourbon uses the CSS edge technique to create triangles in pure CSS. The triangle mixin makes it easy. Here'southward how the mixin works:
.triangle { @include triangle(2em, #ff9900, upward);}
The showtime statement is the triangle size (we've used em here but it could be any valid unit of measurement of measure such equally px or rem), and so the colour and finally the orientation. If you demand to produce a bordered triangle for browsers that support pseudo classes, you can build on this mixin. For example:
.triangle { position: relative; &:earlier { position: accented; @include triangle(34px, #000, up); left: l%; top: -18px; margin-left: -17px; display: cake; content: " "; } &:later { position: absolute; @include triangle(32px, #ff9900, up); left: fifty%; top: -16px; margin-left: -16px; brandish: block; content: " "; }}
That will produce an orange triangle with a black edge (one sat behind the other using absolute positioning).
Like shooting fish in a barrel aureate ratios
The Bourbon golden ratio function makes it easy to create elements that chronicle to 1 another on the gilded scale. Permit'due south await at a basic example. We will employ it to make header styles that are all related to ane another by the aureate ratio.
h1 { font-size: 4rem;}h2 { font-size: gold-ratio(4rem, -i);}h3 { font-size: golden-ratio(4rem, -2);}
That compiles to the following CSS:
h1 { font-size: 4rem; }h2 { font-size: two.47219rem; }h3 { font-size: 1.52793rem; }
Be aware that the integer must be a whole number, so information technology'south not possible to practise font-size: golden-ratio(4rem, -1.five);.
Conclusion
We're just scratching the surface of Bourbon with this whistlestop tour. Besides the raft of like shooting fish in a barrel CSS3 mixins, there are custom timing functions for transitions, vendor prefixed keyframes for animations and a grid organization. Exist sure to have a wait at the documentation at the project's website.
Thank you lot for reading five articles this month* Bring together now for unlimited access
Bask your first calendar month for simply £ane / $1 / €1
*Read v gratuitous articles per month without a subscription
Bring together now for unlimited access
Endeavor first month for merely £ane / $1 / €ane
Related articles
Source: https://www.creativebloq.com/css3/getting-started-bourbon-6135582
Post a Comment for "Bourbon & Beef Tasting at Volare, May 1"