Floating Action Button

Floating action button (FAB) is used for a promoted action. They are distinguished by a circled icon floating above the UI and have motion behaviors that include morphing, launching, and a transferring anchor point.

Layout of floating action button is very simple. Just put it as the direct child of or view:

FAB position is configured via additional fab-[horizontal]-[vertical] class. The following clases are avaialble:

  • fab-right-bottom
  • fab-center-bottom
  • fab-left-bottom
  • fab-right-center
  • fab-center-center
  • fab-left-center
  • fab-right-top
  • fab-center-top
  • fab-left-top

FAB Colors

FAB supports all . To change its color just add color-[color] class to FAB element.

  1. <!-- Red FAB -->
  2. <div class="fab fab-left-top color-red"></div>
  3. <!-- Green FAB -->
  4. <div class="fab fab-right-bottom color-green"></div>

Extended FAB

The extended FAB is wider, and it includes a text label. To make extended FAB we need to add additional fab-extended class to FAB element and put its extra text in <div class="fab-text"> element inside:

The floating action button can fling out related actions upon press. The button should remain on screen after the menu is invoked. Tapping in the same spot should either activate the most commonly used action or close the open menu.

In this case we need to add additional element with buttons:

  1. <div class="fab fab-right-bottom">
  2. <a href="#">
  3. <!-- First icon is visible when Speed Dial actions are closed -->
  4. <i class="icon f7-icons">add</i>
  5. <!-- Second icon is visible when Speed Dial actions are opened -->
  6. <i class="icon f7-icons">close</i>
  7. </a>
  8. <!-- Speed Dial action buttons -->
  9. <div class="fab-buttons fab-buttons-bottom">
  10. <a href="#">1</a>
  11. <a href="#">2</a>
  12. <a href="#">3</a>
  13. </div>
  14. </div>
  • fab-buttons-top - buttons will appear on top of FAB
  • fab-buttons-right - buttons will appear on right of FAB
  • fab-buttons-bottom - buttons will appear on bottom of FAB
  • fab-buttons-left - buttons will appear on left of FAB
  • fab-buttons-center - buttons will appear around of FAB

  • Note that Speed Dial actions buttons will appear in reversed order

  • You shouldn’t use more than 6 Speed Dial actions

  • You should use at least 3 Speed Dial actions

Speed Dial With Labels

Speed dial buttons also support additional text labels. In this case layout will be a bit extended:

FAB Morph

There is also ability for FAB to morph to any visible element on page.

  1. <div class="page">
  2. <div class="navbar">...</div>
  3. <!-- Toolbar has additional required "fab-morph-target" class -->
  4. <div class="toolbar toolbar-bottom fab-morph-target">
  5. </div>
  6. <!-- FAB will morph to toolbar -->
  7. <div class="fab fab-morph" data-morph-to=".toolbar">
  8. </div>
  9. <div class="page-content">
  10. ...
  11. </div>
  12. </div>

Where

  • data-morph-to - additional attribute on FAB where target element’s CSS selector must be specified. In this example it points to Toolbar
  • fab-morph-target - additional required class on FAB morph target, in this example it is added to Toolbar

FAB App Methods

FAB will fire the following DOM events on FAB element:

EventTargetDescription
fab:openFAB Element<div class=”fab”>Event will be triggered on FAB open or when it morphs to target element
fab:closeFAB Element<div class=”fab”>Event will be triggered on FAB close or when it morphs back from target element

Control FAB With Links

It is possible to open and close required FAB (if you have it in DOM) using special classes and data attributes on links:

  • To open FAB speed dial actions we need to add **fab-open** class to any HTML element (prefered to link)

  • To close FAB speed dial or to morph FAB back from target we need to add **fab-close** class to any HTML element (prefered to link)

  • If you have more than one FAB in DOM, you need to specify appropriate FAB via additional **data-fab=".some-fab"** attribute on this HTML element

CSS Variables

Below is the list of related CSS variables (CSS custom properties).

Note that commented variables are not specified by default and their values is what they fallback to in this case.

  1. <div class="page">
  2. <div class="navbar">
  3. <div class="navbar-inner">
  4. <div class="title">Floating Action Button</div>
  5. </div>
  6. </div>
  7. <!-- Toolbar FAB Morph Target -->
  8. <div class="toolbar toolbar-bottom fab-morph-target">
  9. <div class="toolbar-inner">
  10. <!-- Each Toolbar link will close FAB (morph back) on click -->
  11. <a class="link fab-close">Link 1</a>
  12. <a class="link fab-close">Link 2</a>
  13. <a class="link fab-close">Link 3</a>
  14. </div>
  15. </div>
  16. <!-- FAB Left Top (Yellow) -->
  17. <div class="fab fab-left-top color-yellow">
  18. <a href="#">
  19. <!-- Icons For iOS Theme -->
  20. <i class="icon f7-icons if-not-md">add</i>
  21. <i class="icon f7-icons if-not-md">close</i>
  22. <!-- Icons For MD Theme -->
  23. <i class="icon material-icons md-only">add</i>
  24. <i class="icon material-icons md-only">close</i>
  25. </a>
  26. <!-- FAB speed dial actions -->
  27. <div class="fab-buttons fab-buttons-bottom">
  28. <a href="">1</a>
  29. <a href="">2</a>
  30. <a href="">3</a>
  31. </div>
  32. <!-- FAB Right Top (Pink) -->
  33. <div class="fab fab-right-top color-pink">
  34. ...
  35. ...
  36. </div>
  37. </div>
  38. <!-- FAB Center (Green) -->
  39. <div class="fab fab-center-center color-green">
  40. ...
  41. <div class="fab-buttons fab-buttons-center">
  42. ...
  43. </div>
  44. </div>
  45. <!-- FAB Left Bottom (Blue) -->
  46. <!-- Will morph to Toolbar -->
  47. <div class="fab fab-left-bottom fab-morph color-blue" data-morph-to=".toolbar">
  48. ...
  49. </div>
  50. <!-- FAB Right Bottom (Orange) -->
  51. <div class="fab fab-right-bottom">
  52. ...
  53. <!-- FAB speed dial actions with labels -->
  54. <div class="fab-buttons fab-buttons-top">
  55. <a href="#" class="fab-label-button">
  56. <span>1</span>
  57. <span class="fab-label">Action 1</span>
  58. </a>
  59. <a href="#" class="fab-label-button">
  60. <span>2</span>
  61. <span class="fab-label">Action 2</span>
  62. </a>
  63. </div>
  64. </div>
  65. <!-- Extended FAB Center Bottom (Red) -->
  66. <div class="fab fab-extended fab-center-bottom color-red">
  67. <a href="#">
  68. <i class="icon f7-icons if-not-md">add</i>
  69. <i class="icon material-icons md-only">add</i>
  70. <div class="fab-text">Create</div>
  71. </a>
  72. </div>
  73. <div class="page-content">
  74. <div class="block">
  75. <p>Lorem ipsum dolor sit amet...</p>
  76. </div>