-1
I’m creating a page that will have a fixed sidebar and a <div>
with the main content of the page. Below is an example code:
.sidenav {
height: 100%;
width: 160px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
padding-top: 20px;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}
<div class="sidenav">
<a href="#about">About</a>
<a href="#services">Services</a>
<a href="#clients">Clients</a>
<a href="#contact">Contact</a>
</div>
<div class="main">
<p>Aqui estará o conteúdo principal da minha página.</p>
</div>
The problem is, as you can see, the <div>
is not positioned next to the sidenav
.
For that, I would need to insert a margin-left
with the exact width of the sidebar on <div>
, but that’s not what I want. I want the <div>
is automatically positioned next to the sidenav
, so that it is not necessary to change its CSS code if there is a change in the size of the sidebar.