% @side_nav = "css" %>
A simple way to add a progress bars to your layouts. You only need two HTML elements to make them and they're easy to customize.
There are two ways to add progress bars labels in Foundation 4: with our predefined HTML classes or with our mixins. Building progress bars using our predefined classes is simple, you'll just need to write a <div class="progress">
and inside of that a <span class="meter">
. The meter is the element that you can set a width to, either inline or programmatically on your own accord. The simplest way to do this is to change the style="width:%"
property on the meter, itself.
The class options:
.secondary, .alert
or .success
.radius
or .round
..small-#
or .large-#
For these styles to come across, make sure you have the default Foundation CSS package or that you've selected labels from a custom package. These should be linked up following our default HTML page structure.
We've included SCSS mixins used to style progress bars. To use the mixin, you'll need to have the extension installed or grab _variables.scss, _global.scss and _progress-bars.scss from Github and throw them into a Foundation folder in your project directory. From there, you can import the files at the top of your own SCSS stylesheet, like so:
<%= code_example ' @import "foundation/variables", "foundation/components/global", "foundation/components/progress-bars"; ', :css %>Progress bars are made from a container and a meter. The container element holds most of the styles that come across and holds the meter, itself. You can create progress bars by creating a <div>
and giving it a unique class or ID, then applying the mixin styles to it.
The next step is to include an element inside of your container that will be styled as the meter. <%= code_example ' .your-class-name { @include progress-container; & > span { @include progress-meter($bg); } } /* We can set the background color of the meter to a variable or any color value */ $bg: $primary-color ', :css %>
Like we mentioned on a few of the other component pages, you have access to some global mixins that can add even more style to elements like this. Here's an example of using border radius:
<%= code_example ' .your-class-name { @include progress-container; @include radius(6px); & > span { @include progress-meter(pink); @include radius(5px); } }', :css %>Note: emCalc();
is a function we wrote to convert px
to em
. It is included in _variables.scss.