Hide and show vertical menu on mouse hover using simple css

This is one of the vertical menu to show hide the menu text on hover the particular icon in the vertical menu. This is very simple to create with the help of pure css code. When you hover the icon it shows the menu bar. When you leave the icon it hides the menu and show only icon. Most of the website, web application projects developers using this types of menus. Now will show how to create this menu with the help of simple css code. 

First we will write html code to display icons and menus. So the below code is used to display the menus and icons. 


<li>
<a href="http://www.sanwebcorner.com">
<i class="fa fa-bar-chart-o fa-2x"></i>
<span class="nav-text">
Graphs and Statistics
</span>
</a>
</li>

In the nav-text span is the orginal navigation text. This text only we should hide and display on the mouse hover. So that we need some css code for this. On hover the menus are expanding using this below css code . The css code says the extend the width on hover the menu icon. the below code specified the width of the menu is 250px. Before that it was 60px, So the menu expands when on hover the icon. The expands have some css animation, So some transition applied for this. 

.main-menu:hover,nav.main-menu.expanded {
width:250px;
overflow:visible;


}





Here i provided the full code to develop this types of hide and show vertical menu. This example have the demo link. Please check out the demo links to shows the result of the menu. You can download the menu by clicking the download button. I hope this menu is very useful.


Html code for Hide/show vertical menu using simple css:

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Hide and show vertical menu on mouse hover</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<html>
<head>
</head>
<body><div class="area"></div><nav class="main-menu">
<ul>
<li>
<a href="http://www.sanwebcorner.com">
<i class="fa fa-home fa-2x"></i>
<span class="nav-text">
Dashboard
</span>
</a>
</li>


<li class="has-subnav">
<a href="http://www.sanwebcorner.com">
<i class="fa fa-laptop fa-2x"></i>
<span class="nav-text">
Stars Components
</span>
</a>
</li>


<li class="has-subnav">
<a href="http://www.sanwebcorner.com">
<i class="fa fa-list fa-2x"></i>
<span class="nav-text">
Forms
</span>
</a>
</li>


<li class="has-subnav">
<a href="http://www.sanwebcorner.com">
<i class="fa fa-folder-open fa-2x"></i>
<span class="nav-text">
Pages
</span>
</a>
</li>


<li>
<a href="http://www.sanwebcorner.com">
<i class="fa fa-bar-chart-o fa-2x"></i>
<span class="nav-text">
Graphs and Statistics
</span>
</a>
</li>


<li>
<a href="http://www.sanwebcorner.com">
<i class="fa fa-font fa-2x"></i>
<span class="nav-text">
Quotes
</span>
</a>
</li>


<li>
<a href="http://www.sanwebcorner.com">
<i class="fa fa-table fa-2x"></i>
<span class="nav-text">
Tables
</span>
</a>
</li>


<li>
<a href="http://www.sanwebcorner.com">
<i class="fa fa-map-marker fa-2x"></i>
<span class="nav-text">
Maps
</span>
</a>
</li>


<li>
<a href="http://www.sanwebcorner.com">
<i class="fa fa-info fa-2x"></i>
<span class="nav-text">
Documentation
</span>
</a>
</li>
</ul>

<ul class="logout">
<li>
<a href="http://www.sanwebcorner.com">
<i class="fa fa-power-off fa-2x"></i>
<span class="nav-text">
Logout
</span>
</a>
</li>
</ul>
</nav>

<h2 style="margin-left:40%;"><a href="http://www.sanwebcorner.com">www.sanwebcorner.com</a></h2>
</body>
</html>
</body>
</html>


Css Code for show / Hide menu:

.fa-2x {
font-size: 2em;
}
.fa {
position: relative;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
font-size:20px;
}


.main-menu:hover,nav.main-menu.expanded {
width:250px;
overflow:visible;
}

.main-menu {
background:#FF8100;
border-right:1px solid #FF5E00;
position:absolute;
top:0;
bottom:0;
height:100%;
left:0;
width:60px;
overflow:hidden;
-webkit-transition:width .05s linear;
transition:width .05s linear;
-webkit-transform:translateZ(0) scale(1,1);
z-index:1000;
}

.main-menu>ul {
margin:7px 0;
}

.main-menu li {
position:relative;
display:block;
width:250px;
}

.main-menu li>a {
position:relative;
display:table;
border-collapse:collapse;
border-spacing:0;
color:#fff;
 font-family: arial;
font-size: 14px;
text-decoration:none;
-webkit-transform:translateZ(0) scale(1,1);
-webkit-transition:all .1s linear;
transition:all .1s linear;
  
}

.main-menu .nav-icon {
position:relative;
display:table-cell;
width:60px;
height:36px;
text-align:center;
vertical-align:middle;
font-size:18px;
}

.main-menu .nav-text {
position:relative;
display:table-cell;
vertical-align:middle;
width:190px;
  font-family: 'Titillium Web', sans-serif;
}

.main-menu>ul.logout {
position:absolute;
left:0;
bottom:0;
}

.no-touch .scrollable.hover {
overflow-y:hidden;
}

.no-touch .scrollable.hover:hover {
overflow-y:auto;
overflow:visible;
}

a:hover,a:focus {
text-decoration:none;
}

nav {
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
-o-user-select:none;
user-select:none;
}

nav ul,nav li {
outline:0;
margin:0;
padding:0;
}
.main-menu li:hover>a,nav.main-menu li.active>a,.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus,.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus,.no-touch .dashboard-page nav.dashboard-menu ul li:hover a,.dashboard-page nav.dashboard-menu ul li.active a {
color:#fff;
background-color:#FF9800;
}
.area {
float: left;
background: #e2e2e2;
width: 100%;
height: 100%;
}
@font-face {
  font-family: 'Titillium Web';
  font-style: normal;
  font-weight: 300;
  src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v2/anMUvcNT0H1YN4FII8wpr24bNCNEoFTpS2BTjF6FB5E.woff) format('woff');
}

Post a Comment

2 Comments