There are two ways to build buttons in Foundation 4: with our predefined HTML classes or with our structure and mixins. Building buttons using our predefined classes is simple, you'll need an <a>
, <button>
or <input>
with a class of .button.dropdown
. This will create a default medium button. You can also use size, color and radius classes to control more of the style.
The classes options:
.tiny, .small, .medium
or .large
.secondary, .alert
or .success
.radius
or .round
.You may chain one class from each group to build up desired default styles. For these styles to take effect, make sure you have the default Foundation CSS package or that you've selected dropdown buttons from a custom package. These should be linked up following our default HTML page structure.
We've included SCSS mixins used to style buttons. To use these mixins, you'll need to have the extension installed or grab _foundation-global.scss, _buttons.scss and _dropdown-buttons.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/foundation-global", "foundation/buttons", "foundation/dropdown-buttons"; ', :css %>If you are using the mixins, you may include the styles on whatever class or ID you'd like, just make sure you follow our markup structure:
<%= code_example ' Button Text ', :html %>You can quickly build entire dropdown buttons using our global mixin by including it on your custom class or ID in your stylesheet. The global mixin will create the necessary style for the button. The global mixin looks like this:
<%= code_example ' /* Using the default styles */ .your-class-name { @include button; @include dropdown-button; } ', :css %> Default Dropdown ButtonThere are also three options you can customize on the fly when writing this mixin. These control things like: background color, pip color and base styles. Setting any of these options to false will not include the styles.
<%= code_example ' /* Using the available options */ .your-class-name { @include button; @include dropdown-button($padding, $pip-color, $base-style); } /* This controls padding around the dropdown buttons. Use tiny, small, medium, or large */ $padding: $button-med /* This controls the dropdown pip color. Set to one of our variables or a custom hex value */ $pip-color: #fff /* This controls whether or not base styles come through. Set to false to negate */ /* Handy when you want to have many different styles */ $base-style: true ', :css %>Sometimes you want to add a nice fancy shine to the edge of your button. And sometimes you want to make that shine look like it gets depressed upon tap or click. We've got you covered with our quick inset shadow mixin. You can use our radius mixin to quickly apply rounded corners or a transition mixin to give the button a nice zero-fade.
<%= code_example ' .your-class-name { @include button; @include dropdown-button; @include radius; @include single-transition; @include inset-shadow; } ', :css %> Button Base, Size, Style & ShineNote: emCalc();
is a function we wrote to convert px
to em
. It is included in _foundation-global.scss.
You don't need ths JS to create dropdown button styles with Foundation. The only reason you'll need to include foundation.dropdown.js
is if you want to add one of our dropdown to the button. You'll also need to make sure to include zepto.js
and foundation.js
above the dropdown plugin. Above your closing </body>
tag include the following line of code and make sure you have the JS in your directory:
Read how to install Foundation JavaScript
Required Foundation Library: foundation.dropdown.js
To create the dropdown, you'll need to attach a data-attribute to whatever element you want the dropdown attached to (in this case a button). From there you'll create a list that holds the links or content and add another data-attribute that associates with the element it belongs to. Here's an example of that markup:
<%= code_example ' Dropdown ButtonRequired Foundation Library: foundation.dropdown.js
You'll notice that data-dropdown="drop1"
and id="drop1"
have similar values. This is what tells the dropdown plugin where to look to find the position to attach the dropdown element to.
Dropdown options can only be passed in during initialization at this time.
<%= code_example " { activeClass: 'open' }", :json %>