How to create: Icon navigation bar
- Previous Page CodeW3C.com Treasure Box
- Next Page Menu Icon
Learn how to use CSS to create an icon navigation bar.
Vertical:
Horizontal:
How to create an icon bar
Step 1 - Add HTML:
<!-- Add icon library --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <div class="icon-bar"> <a class="active" href="#"><i class="fa fa-home"></i></a> <a href="#"><i class="fa fa-search"></i></a> <a href="#"><i class="fa fa-envelope"></i></a> <a href="#"><i class="fa fa-globe"></i></a> <a href="#"><i class="fa fa-trash"></i></a> </div>
Step 2 - Add CSS:
Vertical instance
.icon-bar { width: 90px; /* Set specific width */ background-color: #555; /* Dark gray background */ } .icon-bar a { display: block; /* Make links vertically aligned instead of parallel */ text-align: center; /* Center align text */ padding: 16px; /* Add inner padding */ transition: all 0.3s ease; /* Add transition animation for hover effect */ color: white; /* Text color is white */ font-size: 36px; /* Increase font size */ } .icon-bar a:hover { background-color: #000; /* Add hover color */ } .active { background-color: #04AA6D; /* Add activity/current color */ }
Horizontal instance
.icon-bar { width: 100%; /* Full width */ background-color: #555; /* Dark gray background */ overflow: auto; /* Overflow caused by floating */ } .icon-bar a { float: left; /* Float links in parallel */ text-align: center; /* Center align text */ width: 20%; /* Equal width (5 icons, each icon width is 20% = 100%) */ padding: 12px 0; /* Some top and bottom inner padding */ transition: all 0.3s ease; /* Add transition animation for hover effect */ color: white; /* Text color is white */ font-size: 36px; /* Increase font size */ } .icon-bar a:hover { background-color: #000; /* Add hover color */ } .active { background-color: #04AA6D; /* Add activity/current color */ }
Related Pages
Tutorial:CSS Navigation Bar
Tutorial:Icon Tutorial
- Previous Page CodeW3C.com Treasure Box
- Next Page Menu Icon