Navigation Bar With Megamenus And Tabs

1

How to start working with us.

Geolance is a marketplace for remote freelancers who are looking for freelance work from clients around the world.

2

Create an account.

Simply sign up on our website and get started finding the perfect project or posting your own request!

3

Fill in the forms with information about you.

Let us know what type of professional you're looking for, your budget, deadline, and any other requirements you may have!

4

Choose a professional or post your own request.

Browse through our online directory of professionals and find someone who matches your needs perfectly, or post your own request if you don't see anything that fits!

Multiple columns of information and links can be overwhelming if they're not grouped into categories and subcategories and then finally into individual items. That's where the tabbed interface works, especially for larger sites with multiple levels of menus. This tutorial will show you how to build a simple tabbed navigation menu using CSS and HTML.

Are you looking for an easy way to organize your website's information?

Geolance offers an intuitive tabbed interface that will make it easy for your visitors to find the information they're looking for. Our tabbed navigation menu is easy to set up and can be customized to match the look and feel of your website.

With Geolance, you can create a professional-looking tabbed navigation menu in minutes. Our simple drag-and-drop interface makes it easy to add and delete tabs, change the order of tabs, and customize the appearance of your menu. Plus, our menus are responsive so they'll look great on any device.

Conclusion

This tutorial will show you how to build a simple tabbed navigation menu using CSS and HTML. You can use these techniques to create a three-tabbed horizontal existing menu or a full-width mega dropdown menu going from the edge of the page to almost halfway down, depending on your content. The tabs themselves are built with lists and anchors, while the layout is handled by floating tables in combination with negative margins for clearing floats. For example, WordPress mega menu can be an excellent prompt you can use to create mega menus on your own.

Dropdown mega-dropdown active is a principle to provide you with nav links and tabs menus. A tab menu is an option of a WordPress menu which enables you to use navbar toggle collapsed. Carrousel menus is another options with a dropdown toggle.

We start this tutorial by creating normal UL lists that serve as tabs when they're nested within another list. First, we need to add display: inline; to ul li elements to remove their default vertical presentation because we want them laid out horizontally. Then we position each LI relative to its UL parent so they act like tabs. We'll make the active tab look different by adding a class name to the UL LI that becomes the active tab, and then we'll add background colors to both LI elements.

We also want to make sure these tabs stay put at the top of the page while allowing for some content above it (a logo in our case), so we use position: relative; on the UL LI containing them. This allows us to set explicit top positioning on all its children by using negative margins, which will push them down below their parent's height.

To finish up, we just need to give each list item an ID for easy referencing in our CSS file and remove margins from all but the last LI inside each UL so they float side by side. This is what our HTML looks like:

We end up with a list of tabs that look fairly normal. Now let's add some CSS to make them work as tabs, which means making the active tab stick, and applying styling to the inactive ones so they appear disabled.

We give each UL LI its width to center it within its parent UL while setting the default value of text-align to right keeps things neat on both sides of the tabbed interface. The next step is floating all these ULs left into their horizontal presentation, but we want to float them inside another element because we don't want other elements trying to wrap around their outside edges. That's why we enclose our Tabs in a div with a class name of the wrapper.

Then we'll add some additional CSS to handle the positioning and enable/disable styles for each tab. We enforce position: relative; on UL LI so our absolute positioning values work, and then we set explicit top positioning to move everything down below the tabs. For inactive tabs, we give them a slightly smaller font size and apply shadow effects to mimic disabled elements. In doing so, they're visually hidden but still clickable, which works nicely in almost all browsers. This is what you get when you add the CSS shown here:

We end up with an interface that's easy to navigate while remaining very simple aesthetically (no images required). Moreover, each tab still acts like a normal list item to allow for keyboard navigation, which is a nice touch. This tutorial demonstrates just the beginning of what you can do with this effect. You could have much more advanced styling by changing colors and applying background images to each tab, as well as different types of bullets as active elements. Also, you might want to try scaling up your design so it runs from edge to edge across the entire page instead of being confined inside a specific container.

In our example, we have three tabs, but feel free to add more via copy/paste if you need a lot of options on one page. Don't be afraid to experiment with this effect—it's extremely easy and flexible once you understand how it works. If you're an intermediate to an advanced developer, you'll be able to do some very interesting things with this approach.

Accessibility

Always an issue when you use tabbed interfaces, but adding a quick wrapper element with role="tablist" to the UL LI containing our Tabs makes this technique even friendlier to search engine bots and browsers like Opera.

The tabs in this example might not be the most aesthetically pleasing list elements we'll ever see (though you can make yours look nicer by applying background images), but they serve their purpose well and could easily become part of any larger design. His article will go on to show how to add drop-down menus using similar techniques for additional effects.

Keep Mega Menus Simple

Mega menus need to keep things simple and easy to navigate, so avoid using too many ULs inside a single UL LI. We tried doing that in the demo for this tutorial and it became messy fast—the interface was difficult to use.

This technique is one of my favorites lately because it's nice and clean, very flexible, and intuitive to use. I think you'll agree once you've given it a try!

If you'd like to see more list-based navigation effects, check out some of our other CSS examples:

CSS Vertical Menus with Tabs (Hover Menus)  (shows how you can make tabbed interfaces smaller or larger by changing their font size).

CSS Menu Bar With Tabs  (shows how you can change the number of tabs by adjusting a simple class name).

Vertical CSS Menu Bar With Tabs  (demonstrates how to use this same technique for vertical menus, among other things).

Columns of Tabs  

(shows how to use this same technique for a list of tabs that breaks across multiple columns, where each tab shows up in the browser as its line).

CSS Horizontal Menu Bar With Tabs (Styled Links)  (demonstrates a completely different look and feel for a horizontal menu bar with tabs. The example here uses CSS images instead of text strings for icons.)

CSS Underline Links  (shows how to style links with underlines, giving them a nice pixel effect).

Width Only One Element at a Time

You can't have each UL LI shown on the same screen, because you'll end up with multiple containers for your Tabs. Instead, make sure to define the width of only one container at a time, otherwise, you'll get some funky behavior in browsers like IE 6.

This is true for all CSS-based navigation interfaces—you always need to define the width of only one UL/LI element at a time or else some weird things happen when browser styles are applied. If this happens while you're working on an interface, try narrowing down which CSS rule might be causing it by checking out its source and seeing what property sets that particular part of your page. Eventually, you'll narrow it down and be able to fix it.

For a list of all the containers being used, you can always turn on browser debug mode and have a look at the page's source—most browsers let you view this info by right-clicking somewhere on the interface and selecting View Page Source. That will give you a nice, long list of all styles used for that particular page layout.

Markup:  A List With Three Tabs (Tab 1, Tab 2, And Tab 3) Content: A multi-level navigation system is built from UL LI elements inside ULs. In this example, we're using an unordered (bulleted) list as our base markup. We could easily use other types of lists if we wanted to (e.g., ordered, definition) but the unordered list is generally best because it's flexible and easy to work with. Style: We're using an unordered list like our base markup, for all effects (e.g., navigation bars). The only exception here is that we need to apply a different style rule to make sure Mozilla Firefox understands our tabs—we use class="nav" on the LI containing the tabbed menu interface so Firefox will know how to display them correctly.

I'm sure you've noticed by now that there are no CSS rules directly targeting any of these elements; instead, everything has its properties assigned through contextual selectors inside other rules. This makes it much easier to read and understand what's going on when working with a large number of elements because it's much easier to tell which rules affect which parts of the page.

Background

We're simply using a colorful gradient background in this example because it gives the page some visual interest and makes our tabs stand out more. Foreground: Our foreground elements are defined by the colorizing effect used for our links, which is very similar to what we did with earlier examples (e.g., Vertical Menu Bar). The only difference here is that we've added an underline with text decoration so each link can be easily identified when it's hovered over.

Text Styling: Each tab name has its own style rule applied to it—this is done through contextual selectors inside of other rules. We also use contextual selectors to give them different font families, sizes, etc. Have you ever tried to style text through element selectors alone? Try it now and see what happens, I'll wait.

Unfortunately, the result is not quite as pretty as you might hope for with large fonts—browsers will often reflow your text so it all fits within a single line (which is usually great for most sites). The only way around this seeming limitation is to change the font size of elements like headings or paragraphs instead; then, use descendant selectors that target links inside those textual elements. For example:

P { font-size:18px; }  A {  font-family:"Times New Roman",Georgia,Serif;  } Instead of doing this... A {  font-family:"Times New Roman",Georgia,Serif;  font-size:24px;}

...use the above rules instead. This will work much better than trying to change only the font size of every single link on your page—it's just too impractical and hard to maintain because if you ever decide to swap out your primary font family with something else, your links will break.

Metadata

To keep track of each tab, we're using title attributes with a unique class name. This makes it very easy to style particular tabs without having to know their order or rely on ids that could potentially have been changed through JavaScript programming. By adding the class names directly to our markup, we can change them as needed just by switching out a few selectors inside our CSS file(s) later on—the only drawback being that the styles will break if those classes are removed from any existing pages where they've been used.

Of course, you don't always have to use title attributes—you could also add your metadata as custom data- attributes instead. HTML5 allows for both as long as they have valid values (no spaces or reserved characters allowed).

Stylesheet Structure

Our example is built using two separate stylesheets. The first style sheet contains all of our general, site-wide CSS rules—these are the properties that will affect every single page on your website (e.g., fonts, colors, backgrounds, etc.). The second stylesheet contains the rules for our navigation bar interface; these are only applied to the markup generated by our generator script when users view pages in a browser window. This makes it possible for us to write one set of global property/value pairs and then create different variations later on—it's much easier than writing each rule individually!

(Note: I've also included some additional alternate stylesheets at the end if you want to try them out for yourself.)

The HTML Markup

Our entire markup is structured into three parts: header, nav, and content. The nav element contains the navigation bar that we're building, while the content section holds our text of choice (e.g., "Home"). Our header element defines the page's title using an h1 heading along with some introductory paragraph text for context. Let's take a look at how these different elements are defined inside of our HTML5 markup:

      <header>          <h1>8/100 Navigation Menus</h1>          <p>A quick demonstration on how many popular sites use mega menus and tabbed navigations in their interfaces!</p>          <p>Written by <a href="http://webuildonline.co/" title="We Build Online">Sam Bonham</a></p>     </header>

Tabs

Let's now begin styling the nav element that contains our navigation bar interface! We'll start out with some basic properties to get things moving along:

          $nav-width: 150px;         $nav-height: 100%;         $nav-padding: 1em;

          $active-bg-color:#D69999;

          .mega { font-size:30px; }

          .mega ul { margin:0 0 4em 0;}

          .mega li a, .mega li {   display: block;  margin: 0;       font-family:"Myriad Pro",Arial,sans-serif; }

          .mega li a { background:#19001B;}

          .mega ul a { color:#F5F5F5;}

Before we move on to the text content, let's adjust our default styles a bit. We want to remove the padding from the inside of our mega menu so it doesn't have any extra spacing around its contents—this way it will sit flush right against the edges of our navigation bar. In addition, we also want each list item inside of our mega menu to be 100% wide/horizontal too—otherwise, they'll stack vertically instead and cover up the previous list item's link. This makes it so that each tab is allowed to fill up 100% of its containing element on all sides.

Styling our Tabs

We'll now style our tabs by adding some custom fonts, colors, and spacing to them:

          .mega ul li {      font-size:1.2em;      line-height: 1.8em;}

          .mega ul li a {      padding:0 0 3px 0;      margin:0;}

          .mega ul li a img { max-width:100%; }

          h3, h4{ text-transform : uppercase;}

          h3{ color:#3B496F;}

          .mega li a:hover, .mega li a:active {      background-color:#19001B;     color:#fff;}

We also want to remove the default margin/padding from each list item inside of our mega menu. This way it will sit right up against the edges of its container by default, instead of being 1em away from them. In addition, we need to adjust the font size and line height so that each title fits inside nicely so it doesn't get cut off.

Last but not least, allow us to adjust the look of our tabs when they're hovered over or active so they appear solid black instead of grey! It's technically all part of the same selector, so we can just include it in this step and move on.

Making Room for our Tabs

Now let's adjust the properties of our content section by giving each paragraph some extra padding to separate it from the tabs:

          .content {          padding:0 3em 2em 2.5em;}

          img{ max-width:100%;}

          p{ font-family:'Cinzel',Georgia,serif; }

      <article class="content">       <h3>Home</h3>      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.a facilisis in pretium nisl aliquet. Nullam dignissim convallis est. Quisque rutrum.</p>      <h3>About</h3>      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam dignissim convallis est. Quisque rutrum.</p>

          .mega ul li a:hover {     background:#19001B;}

We want to add some padding between each paragraph and the beginning of the mega menu so there is enough room for our user's mouse or finger to catch and click on it easily. This way we don't end up scrolling or having to wait for our tap/click on the menu item before it reveals itself to us.

Mega menus beat regular dropdowns

In every way especially in terms of how much faster they are to load/render, how quickly they're ready for interaction, and how much less markup is used overall. All of this means that our sites will become faster while simultaneously offering a more enjoyable user experience!

Grouping the options within a Mega Menu

As we discussed before, it becomes tedious if each menu item is linked to a different URL. Instead, let's group them into tabbed sub-sections that are redirected to different pages instead. This way our users will only see a one-page load when they click on the dropdown menu items—making it much faster for them!

Setting up Mega Menu Items

The first thing we'll do here is set up the properties of our .navbar class so it takes up 100% of its containing element and sit flush against the top edges by default:

          #megaMenu ul {     margin:0;     padding: 0;}

          #megaMenu li{     float : left;     width:%;}

We then need to adjust the properties of each submenu item inside of our mega menu. This way it will sit right up against the edges of its containing element by default, instead of being 1em away from them.

          #megaMenu li ul{     width:%;}

          .home {     background-color:#1C4E55;}

We want to make each tab's background color different so it's easier for users to tell which one they clicked on (you could also do this with text colors). For instance, we've set the first/main tab to be blue and then midnight blue for the link that sits right below it. This makes it so you can immediately see where your mouse cursor is located when hovering over it.

Setting up our Tabs

Now we'll adjust the properties of each tab so they sit flushed against the top edge of their container by default instead of being 1em away from them:

          .tab1,      .tab2{     margin-bottom:0;}

          img{ max-width:100%;}

          p{ font-family:'Cinzel',Georgia,serif;}

      <article id="megaMenu" class="navbar">       <h3>Home</h3>      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.a facilisis pretium nisl aliquet. Nullam dignissim convallis est. Quisque rutrum.</p>      <h3>About</h3>      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam dignissim convallis est. Quisque rutrum.</p>

          <ul class="nav nav-tabs">                    <li class="active"><a href="#tab1">Home</a></li><li ><a href="#tab2">About</a></li>

          .tab1{     background:#19001B;}

          .tab2{     background: #f9f7fd;}

Tabbed Content within our Tabs

Now we'll adjust the property of each tab so it floats to the right and becomes flush against its container:

          .tab1{     float:right;     width:50%;}

          #content,      .description {     height:100%;}

          #megaMenu li ul{ width:35%;}

We want to add a height value to our main content div (and remove the padding). This way it will take up all available space inside of its parent element which is exactly what we want. Now we can also adjust the values of our submenu using percentage units rather than pixels. This ensures that they will automatically adjust their width according to the screen that they are being viewed on.

Geolance is an on-demand staffing platform

We're a new kind of staffing platform that simplifies the process for professionals to find work. No more tedious job boards, we've done all the hard work for you.


Geolance is a search engine that combines the power of machine learning with human input to make finding information easier.

© Copyright 2022 Geolance. All rights reserved.