Open In App

Foundation CSS Top Bar

Last Updated : 10 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Foundation CSS is an open-source and responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to layout stunning responsive websites, apps, and emails that appear amazing and can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is built on Saas-like bootstrap. It is more sophisticated, flexible, and easily customizable. It also comes with CLI, so it’s easy to use it with module bundlers. It offers the Fastclick.js tool for faster rendering on mobile devices. One such important component of the Foundation is Top Bar.

In this article, we will learn about the top bar component of the Foundation CSS. Top Bar in Foundation CSS helps to wrap the flexible menu components inside a container. The top bar in Foundation CSS contains two sections namely the right section and the left section. On the small screen devices, these two parts are stacked upon each other.

Foundation CSS Top Bar Elements:

Foundation CSS Top bar classes:

  • top-bar: This class is used in the div tag inside which the whole top bar code is written.
  • top-bar-left: This class is used to define the left section of the top bar.
  • top-bar-right: This class is used to define the right section of the top bar.

Syntax:

<div class="top-bar">
    <div class="top-bar-left">
         ...    
    </div>
    <div class="top-bar-right">
         ...
    </div>
</div>

Responsive and Advanced Layout: To create a responsive top bar, which will have a toggle click menu bar on a mobile screen ( i.e small screen), we need to create a top bar with a unique ID. We create a title bar element using the class “title-bar” and add the attribute “data-responsive-toggle” and set its value to the unique ID of the top bar. Lastly, you need to add the attribute “data-toggle” to the element which will trigger the toggle and set its value to the unique ID of the top bar.

Syntax:

<div class="title-bar" data-responsive-toggle="examplebar">
    <button class="..." type="button" data-toggle="examplebar">
    </button>
      <div class="title-bar-title">...</div>
 </div>
 <div class="top-bar" id="examplebar">
    <div class="top-bar-left">
      ...
    </div>
    <div class="top-bar-right">
      ...    
    </div>
</div>

Stacking: Two sections of the top bar will get stacked upon each other on small screens by default. Now, to enable custom stacking in different screen sizes, we can use the classes.

  • stacked-for-medium: This class will make the two sections of the Foundation CSS top bar to get stacked upon each other in medium size screen.
  • stacked-for-large: This class will make the two sections of the Foundation CSS top bar to get stacked upon each other on the large screen.

Example 1: Below given is the example of a simple top bar with 3 menus one menu has a drop-down in the left section and the right section of the top bar contains a search box and a search button.

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href=
        crossorigin="anonymous">
         
    <script src=
    </script>
    <script src=
            crossorigin="anonymous">
    </script>   
</head>
 
<body>
    <div class="top-bar" style="background-color:rgb(143,253,167);">
        <div class="top-bar-left" >
            <ul class="dropdown menu" data-dropdown-menu>
                <li class="menu-text" style="color:green;">
                    GeeksforGeeks
                </li>
                <li>
                    <a href="#">Articles</a>
                    <ul class="menu vertical">
                        <li><a href="#">HTML</a></li>
                        <li><a href="#">CSS</a></li>
                        <li><a href="#">js</a></li>
                        <li><a href="#">Bootstrap</a></li>
                        <li><a href="#">Foundation CSS</a></li>
                    </ul>
                </li>
                <li><a href="#">Practice</a></li>
                <li><a href="#">Interview Experience</a></li>
            </ul>
        </div>
        <div class="top-bar-right">
            <ul class="menu">
                <li><input type="search" placeholder="Search"></li>
                <li><button type="button" class="button">Search</button></li>
            </ul>
        </div>
    </div>
 
    <script>
        $(document).foundation();
    </script>
 
</body>
</html>


Output:

 

Example 2: We have created the same top bar as in the above example but made it responsive.

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content=
"width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href=
        crossorigin="anonymous">
         
    <script src=
    </script>
    <script src=
         crossorigin="anonymous">
    </script>  
</head>
<body>   
       
    <div class="title-bar" data-responsive-toggle="responsive-menu"
          data-hide-for="medium">
        <button class="menu-icon" type="button" data-toggle="responsive-menu">
        </button>
        <div class="title-bar-title">Menu</div>
    </div>
       
    <div class="top-bar" id="responsive-menu">
        <div class="top-bar-left">
          <ul class="dropdown menu" data-dropdown-menu>
            <li class="menu-text" style="color:green;">
                GeeksforGeeks
            </li>
            <li>
                <a href="#">Articles</a>
                <ul class="menu vertical">
                    <li><a href="#">HTML</a></li>
                    <li><a href="#">CSS</a></li>
                    <li><a href="#">js</a></li>
                    <li><a href="#">Bootstrap</a></li>
                    <li><a href="#">Foundation CSS</a></li>
                </ul>
            </li>
            <li><a href="#">Practice</a></li>
            <li><a href="#">Interview Experience</a></li>
          </ul>
        </div>
        <div class="top-bar-right">
          <ul class="menu">
            <li><input type="search" placeholder="Search"></li>
            <li><button type="button" class="button">Search</button>
            </li>
          </ul>
        </div>
    </div>
     
    <script>
        $(document).foundation();
    </script>
 
</body>
</html>


Output:

 

Sticky Navigation: We can also create a sticky Top Bar using the sticky plugin by learning the Foundation CSS sticky plugin from this article.

Reference: https://get.foundation/sites/docs/top-bar.html 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads