Hamburgers

Tasty CSS-animated Hamburgers

README

Hamburgers


Hamburgers is a collection of tasty CSS-animated hamburger icons. Also included is the source as a Sass library. It’s modular and customizable, so cook up your own hamburger.

undefined

Table of Contents



Usage


1. [Download](https://github.com/jonsuh/hamburgers/blob/master/dist/hamburgers.css) and include the CSS in the `` of your site:

  1. ``` html
  2.   <link href="dist/hamburgers.css" rel="stylesheet">
  3. ```

2. Add the base hamburger markup:

  1. ``` html
  2.   <button class="hamburger" type="button">
  3.     <span class="hamburger-box">
  4.       <span class="hamburger-inner"></span>
  5.     </span>
  6.   </button>  
  7. ```

You *can* use `
`s if you insist, but they’re not [accessible](#accessibility) as a menu button.

  1. ``` html
  2.   <div class="hamburger">
  3.     <div class="hamburger-box">
  4.       <div class="hamburger-inner"></div>
  5.     </div>
  6.   </div>
  7. ```

3. Append the class name of the type of hamburger you’re craving:

  1. ``` html
  2.   <button class="hamburger hamburger--collapse" type="button">
  3.     <span class="hamburger-box">
  4.       <span class="hamburger-inner"></span>
  5.     </span>
  6.   </button>
  7. ```

  Here’s the list of hamburger-type classes you can choose from:

  1. ```
  2.   hamburger--3dx
  3.   hamburger--3dx-r
  4.   hamburger--3dy
  5.   hamburger--3dy-r
  6.   hamburger--3dxy
  7.   hamburger--3dxy-r
  8.   hamburger--arrow
  9.   hamburger--arrow-r
  10.   hamburger--arrowalt
  11.   hamburger--arrowalt-r
  12.   hamburger--arrowturn
  13.   hamburger--arrowturn-r
  14.   hamburger--boring
  15.   hamburger--collapse
  16.   hamburger--collapse-r
  17.   hamburger--elastic
  18.   hamburger--elastic-r
  19.   hamburger--emphatic
  20.   hamburger--emphatic-r
  21.   hamburger--minus
  22.   hamburger--slider
  23.   hamburger--slider-r
  24.   hamburger--spin
  25.   hamburger--spin-r
  26.   hamburger--spring
  27.   hamburger--spring-r
  28.   hamburger--stand
  29.   hamburger--stand-r
  30.   hamburger--squeeze
  31.   hamburger--vortex
  32.   hamburger--vortex-r
  33. ```

  Note: -r classes are reverse variants (e.g. hamburger--spin spins clockwise whereas hamburger--spin-r spins counterclockwise.

4. Trigger the active state by appending class name is-active:

  1. ``` html
  2.   <button class="hamburger hamburger--collapse is-active" type="button">
  3.     <span class="hamburger-box">
  4.       <span class="hamburger-inner"></span>
  5.     </span>
  6.   </button>
  7. ```

  Since the class name would have to be toggled via JavaScript and implementation would differ based on the context of how you plan on using the hamburger, I’m going to leave the rest up to you.

Sass


.scss source files are available if you use Sass as your CSS precompiler. It’s customizable and modular.

1. Hamburgers is available on npm, yarn and Bower.

  1. ```
  2.   npm install hamburgers

  3.   yarn add hamburgers

  4.   bower install css-hamburgers
  5. ```

  Also available as a Ruby gem to use within your Rails application—see below for more information.

  Or to manually install it, download and unzip the source files, then copy the files from the_sass/hamburgers directory into your project.

2. Import the hamburgers.scss file in your Sass manifest file:

  1. ```scss
  2.   @import "path/to/hamburgers";
  3. ```

3. Customize your hamburger and/or remove any types you don’t want in hamburgers.scss.
4. Compile your Sass*, and voila!

\* Be sure to run the CSS through Autoprefixer since the Sass doesn’t account for vendor prefixes.

Install for Ruby on Rails


1. Add Hamburgers to your Gemfile.

  1. ```
  2.   gem 'hamburgers'
  3. ```

2. Run bundle install.
3. Include Hamburgers by using Sass’s native @import:

  1. ```scss
  2.   // application.scss
  3.   @import "hamburgers";
  4. ```

  \ More information on why Sass’s native@import + why you should ditch Sprockets directives altogether.

Customization


To override default settings, declare them before importing Hamburgers:

  1. ```scss
  2. $hamburger-padding-x: 20px;
  3. $hamburger-padding-y: 15px;
  4. $hamburger-types     : (collapse);

  5. @import "hamburgers";
  6. ```

You can also create a separate file (e.g. hamburgers-settings.scss) with those declarations, then import it before Hamburgers:

  1. ```scss
  2. @import "hamburgers-settings"
  3. @import "hamburgers";
  4. ```

Here is the full list of default settings (found in _sass/hamburgers/hamburgers.scss);

  1. ```scss
  2. $hamburger-padding-x           : 15px;
  3. $hamburger-padding-y           : 15px;
  4. $hamburger-layer-width         : 40px;
  5. $hamburger-layer-height        : 4px;
  6. $hamburger-layer-spacing       : 6px;
  7. $hamburger-layer-color         : #000;
  8. $hamburger-layer-border-radius : 4px;
  9. $hamburger-hover-opacity       : 0.7;
  10. $hamburger-active-layer-color  : $hamburger-layer-color;
  11. $hamburger-active-hover-opacity: $hamburger-hover-opacity;

  12. // To use CSS filters as the hover effect instead of opacity,
  13. // set $hamburger-hover-use-filter as true and
  14. // change the value of $hamburger-hover-filter accordingly.
  15. $hamburger-hover-use-filter   : false;
  16. $hamburger-hover-filter       : opacity(50%);
  17. $hamburger-active-hover-filter: $hamburger-hover-filter;

  18. // Remove or comment out the hamburger types you don’t want
  19. // or need, so they get excluded from the compiled CSS.
  20. $hamburger-types: (
  21.   3dx,
  22.   3dx-r,
  23.   3dy,
  24.   3dy-r,
  25.   3dxy,
  26.   3dxy-r,
  27.   arrow,
  28.   arrow-r,
  29.   arrowalt,
  30.   arrowalt-r,
  31.   arrowturn,
  32.   arrowturn-r,
  33.   boring,
  34.   collapse,
  35.   collapse-r,
  36.   elastic,
  37.   elastic-r,
  38.   emphatic,
  39.   emphatic-r,
  40.   minus,
  41.   slider,
  42.   slider-r,
  43.   spring,
  44.   spring-r,
  45.   stand,
  46.   stand-r,
  47.   spin,
  48.   spin-r,
  49.   squeeze,
  50.   vortex,
  51.   vortex-r
  52. );
  53. ```

ems or rems


Wanna work with ems or rems instead of px? Just change all the px values to the unit of your choice. Note: Be consistent (all px or all ems), otherwise it may break—the math behind the customization will fail if it attempts to perform operations with values of different units.

Not satisfied?


Dig into _base.scss or types/ and customize to your heart’s content. Fair warning: It‘s pretty delicate and may break, especially if you tweak the animations themselves.

Accessibility


Hamburger menu icons can be useful in the right context, but they’re not the most accessible.

ARIA will help make it accessible to people with disabilities.

  1. ``` html
  2. <nav>
  3.   <button class="hamburger hamburger--elastic" type="button"
  4.           aria-label="Menu" aria-controls="navigation" aria-expanded="true/false">
  5.     <span class="hamburger-box">
  6.       <span class="hamburger-inner"></span>
  7.     </span>
  8.   </button>
  9. <div id="navigation">
  10.     !--navigation goes here-->
  11.   </div>
  12. </nav>
  13. ```

You will need JavaScript to toggle between aria-expanded attribute being set to true and false, as this will indicate to visually impaired users whether the menu is opened or closed.

The hamburger button belongs __inside__ the `