DEV Community

Sanyam Singh
Sanyam Singh

Posted on

Curved Bottom App Bar With FAB In HTML/CSS

Inspiration

While working on Flutter’s Bottom AppBar I was astounded to see how simple it is to build a curved bottom app bar with fab (floating action button) icon in between. So I decided to try and build it out in html, css to see how well it works. Surprisingly, using css to achieve such design wasn’t as easy as I thought it would be

What do we want to achieve

Alt TextBottom App Bar with Floating action button in the center

Solution

Lets start by adding a div at the bottom with 3 tabs. (left tab, right tab and middle tab that would hold FAB button)

In the above code, you can see 3 tab divs with class .tab--left, .tab--right and the most important one .tab--fab. It contains a div with class .top. Keep this div in mind as we are gonna hack the s**t out of .top div



<div class="tab tab--fab">
  <div class="top">
   <div class="fab"> + </div>
  </div>
</div>


Enter fullscreen mode Exit fullscreen mode

Achieving rounded corners in tabs

So before talking about tab--fab lets first understand how we can achieve curviness in tab--left and tab--right. This can be done using css property border-top-left-radius and border-top-right-radius



.tab--left{
  border-top-right-radius: 30px;
}
.tab--right{
  border-top-left-radius: 30px;
}


Enter fullscreen mode Exit fullscreen mode

Achieving curviness in your FAB tab

There are 3 parts to build a Curved tab with FAB on top of it

Alt Texttab div containing .top div and .fab button

Alt Textdiv.top inside .tab div

Alt TextFAB button inside .tab div

  1. tab — fab: This will contain a div will a class .top and our FAB button
  2. div.top: This will be used to create curve and keep transparency
  3. div.fab: The actual rounded FAB button

Styling our middle tab

Please go through the comments in above code.

As I said before .top is the key as it will produce a curve using border-bottom-left-radius and border-bottom-right-radius. If you do not make this div transparent it will produce a solid shape as shown below, therefore transparency is important

Alt TextResult of .top tab without background: transparent

Designing FAB Button

The above css is to build our rounded FAB button with + icon in the center.

Conclusion

Well, Thats it folks. You can find complete code in below codepen.

Top comments (0)