Fixed position with responsive nav and divs, why is it overlapping?

Viewed 91

I'm trying to make this responsive with a fixed nav. How can I do that without the home column overlapping the navbar? I want the two columns to be flush together and resize with the screen. The nav needs to stay there as I'm adding several "pages" vertically down the one page. I feel like it should be obvious but I've been struggling for a while and I have read almost all of the recent answers and tried so many things and nothing is working for me.

html,
body {
  height: 100vh;
  width: 100vw;
  flex: 1;
  overflow: auto;
}

.nav {
  background-color: #e5b032;
  justify-content: space-between;
  align-items: center;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
}

.nav a {
  color: #000;
  margin: 3rem 1rem;
}

.nav a:hover {
  background-color: #41dbb8;
}

.home {
  background-color: #fb7592;
  flex-direction: column;
  position: relative;
  max-width: 100%;
  height: 100vh;
  align-content: center;
  text-align: center;
  overflow: hidden;
  padding: 0;
}
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Home</title>
<meta name="description" content="Home">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
 </head>

<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-3 d-flex">
            <nav id="navbar" class="navbar navbar-light bg-light">
                <nav class="nav nav-pills flex-column">
                    <a class="nav-link" href="#home">Home</a>
                    <a class="nav-link" href="#projects">Projects</a>
                    <a class="nav-link" href="#blog">Blog</a>
                    <a class="nav-link" href="#bio">About the Developer</a>
                    <a class="nav-link" href="#contact">Contact</a>
                </nav>
            </nav>
        </div>
        
        <div class="home col-md-9 d-flex">
                <h1>This is the content.</h1>
        
        </div>
   </div>
</div>


<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
</body>
</html>

2 Answers

This will be the structure

<div class="row">
  <div class="col-md-3 d-flex">
    <nav id="navbar" class="navbar navbar-light bg-light" style="width:200px">...</nav>
  </div>
<div class="home col-md-9 d-flex" style="overflow: auto;">
      <h1>This is the content.</h1>
    </div>
</div>

remove position: fixed; for .nav class

add overflow: auto; to main content to make scrollable. also give some width to left-nav

html,
body {
  height: 100vh;
  width: 100vw;
  flex: 1;
  overflow: auto;
}

.nav {
  background-color: #e5b032;
  justify-content: space-between;
  align-items: center;
  height: 100vh;
  width: 200px;
  top: 0;
  left: 0;
}

.nav a {
  color: #000;
  margin: 3rem 1rem;
}

.nav a:hover {
  background-color: #41dbb8;
}

.home {
  background-color: #fb7592;
  flex-direction: column;
  position: relative;
  max-width: 100%;
  height: 100vh;
  align-content: center;
  text-align: center;
  overflow: auto;
  padding: 0;
}

.row {
  display: flex;
}
<div class="container-fluid">
  <div class="row">
    <div class="col-md-3 d-flex">
      <nav id="navbar" class="navbar navbar-light bg-light">
        <nav class="nav nav-pills flex-column">
          <a class="nav-link" href="#home">Home</a>
          <a class="nav-link" href="#projects">Projects</a>
          <a class="nav-link" href="#blog">Blog</a>
          <a class="nav-link" href="#bio">About the Developer</a>
          <a class="nav-link" href="#contact">Contact</a>
        </nav>
      </nav>
    </div>

    <div class="home col-md-9 d-flex">
      <h1>This is the content.</h1>
      <h1>This is the content.</h1>
      <h1>This is the content.</h1>
      <h1>This is the content.</h1>
      <h1>This is the content.</h1>
    </div>
  </div>
</div>

Was it necessary? Left sidebar is now fixed with position sticky and top 0

html,
body {
  /*height: 100vh;
  width: 100vw;
  flex: 1;
  overflow: auto;*/
  
   padding: 0;
   margin: 0;
   box-sizing: border-box;
}

.row {
   display: flex;
   width: 100%;
}

.col-md-3.d-flex {
   background-color: #e5b032;
   justify-content: space-between;
   align-items: center;
   height: 100vh;
   position: sticky;
   top: 0;
}

/*.nav {
  background-color: #e5b032;
  justify-content: space-between;
  align-items: center;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
}*/

.nav a {
  color: #000;
  margin: 3rem 1rem;
}

.nav a:hover {
  background-color: #41dbb8;
}

.nav.nav-pills.flex-column {
  display: flex;
}

.home {
  background-color: #fb7592;
  flex-direction: column;
  /*position: relative;*/
  /*max-width: 100%;*/
  width: 100%;
  /*height: 100vh;*/
  height: 150vh;
  align-content: center;
  text-align: center;
  overflow: hidden;
  padding: 0;
}
<div class="container-fluid">
  <div class="row">
    <div class="col-md-3 d-flex">
      <nav id="navbar" class="navbar navbar-light bg-light">
        <nav class="nav nav-pills flex-column">
          <a class="nav-link" href="#home">Home</a>
          <a class="nav-link" href="#projects">Projects</a>
          <a class="nav-link" href="#blog">Blog</a>
          <a class="nav-link" href="#bio">About the Developer</a>
          <a class="nav-link" href="#contact">Contact</a>
        </nav>
      </nav>
    </div>

    <div class="home col-md-9 d-flex">
      <h1>This is the content.</h1>

    </div>
  </div>
</div>

Related