I am trying to create a Side-navbar for a products section of my website. Whenever I create my navbar, the text gets pushed down underneath it. Any ideas?
body {
margin: 0;
}
.sidenav ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 15%;
background-color: #f1f1f1;
position: relative;
height: 75%;
overflow: auto;
}
.sidenav li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
<section>
<section class="sidenav">
<ul>
<li><a href="index.html"><b>HOME</b></a></li>
<li><a href="about.html">ABOUT</a></li>
<li><a href="shop.html">SHOP</a></li>
<li><a href="contact.html">CONTACT</a></li>
</ul>
</section>
<div style="margin-left:15%; margin-top:-10% padding:1px 16px;">
<h2>Products</h2>
<h3>Here is where the product name will be</h3>
<p>Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information.Information</p>
</div>
</section>
I swapped out the section class="sidenav"
with aside class="sidenav"
. Also, you should define a width on your parent and use display: flex;
. Then you can split up the child elements within by giving those a width
also.
body {
margin: 0;
}
.sidenav ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
background-color: #f1f1f1;
position: relative;
height: 100%;
overflow: auto;
}
.sidenav li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
.sidenav {
width: 15%;
}
section > div {
width: 85%;
}
section.wrapper {
display: flex;
width: 100%;
}
<section class="wrapper">
<aside class="sidenav">
<ul>
<li><a href="index.html"><b>HOME</b></a></li>
<li><a href="about.html">ABOUT</a></li>
<li><a href="shop.html">SHOP</a></li>
<li><a href="contact.html">CONTACT</a></li>
</ul>
</aside>
<div>
<h2>Products</h2>
<h3>Here is where the product name will be</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</section>