kessi-cpa Library logo (4.0 KB)

How to Make Menu Bar with Icons and Text

Concept

Adding icons to a menu bar facilitates navigation and improves users' browsing experience.

There are many web icons you can use for free. In this example, we used icons from http://fontawesome.io/icons/ by Dave Gandy.

Note: for the download icon in the button example to properly display, you have to insert the following link in the head section of your page ("Font Awesome by Dave Gandy - http://fontawesome.io):
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>

Example

How To

1. Add HTML

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>

<div class="menuBar">
    <a href="#" class="menuBarButton" onclick="show_page('Home Page')">
        <span><i class="fa fa-home"></i></span>
        <span>Home</span>
    </a>
    <a href="#" class="menuBarButton" onclick="show_page('Products Page')">
        <span><i class="fa fa-product-hunt"></i></span>
        <span>Products</span>
    </a>
    <a href="#" class="menuBarButton" onclick="show_page('About Page')">
        <span><i class="fa fa-info-circle"></i></span>
        <span>About</span>
    </a>
    <a href="#" class="menuBarButton" onclick="show_page('Contact Page')">
        <span><i class="fa fa-envelope"></i></span>
        <span>Contact</span>
    </a>
</div>
<div class="dvPage">
    <label id="lblPage">Home Page</label>
</div>

2. Add CSS

.menuBar
{
    width: 100%;
    height: auto;
    background-color: #ccc;
}

.menuBarButton
{
    height: 60px;
    width: 100px;
    margin: 5px 0;
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    color: #666;
    cursor: pointer;
    font-size: 18px;
    text-decoration: none;
    transition: 0.4s;
}

.menuBarButton:hover
{
    background-color: #666;
    color: #fff;
}

.menuBarButton span
{
      display: block;
}

.menuBarButton i
{
    font-size: 25px;
}

.dvPage
{
    height: 200px;
    width: 100%;
    padding: 15px;
    font-size: 20px;
    border: 1px solid #ccc;
    margin-top: 15px;
}

3. Add JavaScript

<script type="text/javascript">
    function show_page(pg) {
        try {
            document.getElementById("lblPage").innerText = pg;
        }
        catch (err) {
            window.alert(err.message);
        }
    }
</script>
js for dialogbox (39 kb)
Author of this article:
Mahmoud Kessi, CPA, CGA
mkessi@kessi-cpa.com
(204) 226-9576

Comments & Questions

Add New Comment or Question




Post

REPLY/COMMENT



Email Link


Link to be shared:

×

Confirmation

Copyright © 2016-2019 KESSITEK.