How to create: sidebar with icons
- Previous page Hover side navigation button
- Next page Horizontal scrolling menu
Learn how to use CSS to create an icon-based side navigation menu.
How to create a sidebar with icons
Step 1 - Add HTML:
<!-- Load icon library --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <!-- Sidebar --> <div class="sidebar"> <a href="#home"><i class="fa fa-fw fa-home"></i> Home</a> <a href="#services"><i class="fa fa-fw fa-wrench"></i> Services</a> <a href="#clients"><i class="fa fa-fw fa-user"></i> Clients</a> <a href="#contact"><i class="fa fa-fw fa-envelope"></i> Contact</a> </div>
Second step - Add CSS:
/* Sidebar styles - full height */ .sidebar { height: 100%; width: 160px; position: fixed; z-index: 1; top: 0; left: 0; background-color: #111; overflow-x: hidden; padding-top: 16px; {} /* Set the style for sidebar links */ .sidebar a { padding: 6px 8px 6px 16px; text-decoration: none; font-size: 20px; color: #818181; display: block; {} /* Set the link style when the mouse hovers */ .sidebar a:hover { color: #f1f1f1; {} /* Styles for main content */ .main { margin-left: 160px; /* Same as the width of the sidebar navigation */ padding: 0px 10px; {} /* Add media query for small screens (add smaller padding and font size when screen height is less than 450 pixels) */ @media screen and (max-height: 450px) { .sidebar {padding-top: 15px;} .sidebar a {font-size: 18px;} {}
Related pages
Tutorial:CSS navigation bar
Tutorial:How to create icon navigation bar
- Previous page Hover side navigation button
- Next page Horizontal scrolling menu