I have a sidebar with 100% height that includes a div and a ul. The div will display an image at the top of the sidebar, while the ul will contain all the sidebar menu items. It is crucial that the div and ul remain separate and not combined.
The challenge I am facing is ensuring that the last item in the ul always stays at the bottom of the sidebar. I have tried using margin-top: auto to achieve this, and it works when the ul is the only item in the sidebar. However, due to the presence of the div above the ul, the last item in the list gets pushed off the screen.
Is there a way to prevent this issue? My HTML and CSS code are provided below. The goal is to have the flag icon constantly displayed at the bottom of the sidebar while still having both a div and ul included.
Absolutely positioning is not a viable solution as it would cause overlap among items on smaller screens.
body {
margin: 0px;
background-color: #F7F7F7;
}
.container {
height: 100vh;
display: flex;
flex-direction: row;
overflow: hidden;
}
.sidebar {
height: 100%;
flex: 0;
background-color: #464F57;
}
.main {
display: flex;
flex-direction: column;
flex: 1;
margin-left: 20px;
}
.header {
flex: 0;
margin-bottom: 20px;
border-bottom: solid 2px #eaeaea;
}
.content {
overflow-y: auto;
flex: 1;
}
.menu {
display: flex;
flex-direction: column;
list-style: none;
text-align: center;
height: 100%;
margin: 20px 0 0 0;
padding: 0;
}
.menu li:last-child {
margin-top: auto;
}
<link href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" rel="stylesheet"/>
<div class="container">
<div class="sidebar">
<div>
<i class="fa fa-home fa-3x"></i>
</div>
<ul class="menu">
<li><i class="fa fa-camera-retro fa-3x"></i></li>
<li><i class="fa fa-camera-retro fa-3x"></i></li>
<li><i class="fa fa-camera-retro fa-3x"></i></li>
<li><i class="fa fa-camera-retro fa-3x"></i></li>
<li><i class="fa fa-flag fa-3x"></i></li>
</ul>
</div>
<div class="main">
<div class="header">
header
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer maximus aliquam accumsan. Aenean vel dui tellus.
Nulla porttitor ante augue, et posuere ex consequat ac. Nulla eget vestibulum leo. Aliquam </p>
</div>
</div>
</div>