HTML Layout + Aside
by maxell4o
HTML
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
<div class="layout-grid">
<div class="layout-aside">
<ul class="nav flex-column d-block">
<li class="nav-item menu-toggle">
<i class="fas fa-bars"></i>
</li>
<li class="nav-item">link 2</li>
<li class="nav-item">link 3</li>
<li class="nav-item">link 4</li>
<li class="nav-item">link 5</li>
</ul>
</div>
<div class="layout-main">
<div class="layout-header">header</div>
<div class="layout-content">
Lorem ipsum dolor sit amet
</div>
<div class="layout-footer">footer</div>
</div>
</div>
SCSS
html,
body {
height: 100%;
padding: 0;
margin: 0;
}
body {
.layout-aside {
width: 50px;
transition: width .2s ease;
}
.layout-main {
padding-left: 50px;
transition: padding-left .2s ease;
}
.layout-header {
left: 50px;
transition: left .2s ease;
}
&.aside-open {
.layout-aside {
width: 200px;
}
.layout-main {
padding-left: 200px;
}
.layout-header {
left: 200px;
}
}
}
.layout {
&-grid {
display: flex;
flex-direction: column;
flex: 1;
}
&-aside {
position: fixed;
z-index: 95;
left: 0;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
background: #555;
max-width: 100%;
.nav-item {
color: #fff;
font-size: 15px;
padding: 10px;
cursor: pointer;
transition: background .25s ease;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
&.menu-toggle i {
margin-left: 8px;
}
&:not(:first-child) {
border-top: 1px #666 solid;
}
&:hover {
background: #666;
}
}
}
&-main {
display: flex;
flex-direction: column;
flex: 1 auto;
padding: 50px 0 0 0;
}
&-content{
padding: 1rem;
}
&-header {
position: fixed;
top: 0;
right: 0;
height: 50px;
background: #444;
text-align: center;
color: #fff;
}
&-footer {
background: #444;
height: 30px;
text-align: center;
color: #fff;
margin-top: auto;
}
}
JavaScript
$('.menu-toggle').click(function() {
if ($('body').hasClass('aside-open')) {
$('body').removeClass('aside-open');
} else {
$('body').addClass('aside-open');
}
})