toyop
toyop

Reputation: 119

Bootstrap: How to fix two overlapping content

I am trying to create a website using this codepen(enter link description here). The problem I'm having is when I make the window size smaller, the profile section and main content section start to overlap. I think the codepen is using bootstrap grid system here so I don't really understand why this is happening.

content overlapping image

Here are the codes.

HTML

<!--navbar-->
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="mainNav">
  <div class="container">
    <a class="navbar-brand js-scroll-trigger" href="#page-top">Bootstrap</a>
    <div>
      <ul class="navbar-nav text-uppercase ml-auto">
        <li class="nav-item">
              <a class="btn btn-primary my-2 my-sm-0" type="submit"><i class="fa fa-sign-out"></i> Log out</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
<!--our content goes here-->
<div class="container content">
    <div class="row profile">
      <div class="col-md-3">
        <div class="profile-sidebar position-fixed">
          <!-- SIDEBAR USERPIC -->
          <div class="profile-userpic">
            <img src="https://media.rockstargames.com/chinatownwars/global/downloads/avatars/zhou_256x256.jpg" class="img-responsive" alt="">
          </div>
          <!-- END SIDEBAR USERPIC -->
          <!-- SIDEBAR USER TITLE -->
          <div class="profile-usertitle">
            <div class="profile-usertitle-name">
              Jason Davis
            </div>
            <div class="profile-usertitle-job">
              Developer
            </div>
          </div>
          <!-- END SIDEBAR USER TITLE -->
          <!-- SIDEBAR BUTTONS -->
          <div class="profile-userbuttons">
            <button type="button" class="btn btn-success btn-sm">Follow</button>
            <button type="button" class="btn btn-danger btn-sm">Message</button>
          </div>
          <!-- END SIDEBAR BUTTONS -->
          <!-- SIDEBAR MENU -->
          <div class="profile-usermenu sidebar-sticky">
            <ul class="nav flex-column">
              <li class="active nav-item">
                <a href="#" class="nav-link active">
                            <i class="fa fa-home"></i>
                            Overview </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="https://codepen.io/jasondavis/pen/jVRwaG?editors=1000">
                            <i class="fa fa-user"></i>
                            Account Settings </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#" target="_blank">
                            <i class="fa fa-check"></i>
                            Tasks </a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">
                            <i class="fa fa-flag"></i>
                            Help </a>
              </li>
            </ul>
          </div>
          <!-- END MENU -->
        </div>
      </div>
      <div class="col-md-9">
        <div class="profile-content">
          Some user related content goes here...
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
          <h1>test</h1>
        </div>
      </div>
    </div>
  </div>
<div class="container">
  <div class="row">
    <div class="col-md-3">
    </div>
    <div class="col-md-9 ft">
<footer class="footer">
  <div class="row">
    <div class="col-md-4">
      <span class="copyright">Copyright &copy; Your Website 2018</span>
    </div>
    <div class="col-md-4">
      <ul class="list-inline social-buttons">
        <li class="list-inline-item">
          <a href="https://github.com/ELMORABITYounes">
                  <i class="fa fa-github"></i>
                </a>
        </li>
        <li class="list-inline-item">
          <a href="https://www.facebook.com/younes.elmorabit.92">
                  <i class="fa fa-facebook"></i>
                </a>
        </li>
        <li class="list-inline-item">
          <a href="https://www.linkedin.com/in/younes-elmorabit-2a162310b/">
                  <i class="fa fa-linkedin"></i>
                </a>
        </li>
      </ul>
    </div>
    <div class="col-md-4">
      <ul class="list-inline quicklinks">
        <li class="list-inline-item">
          <a href="#">Privacy Policy</a>
        </li>
        <li class="list-inline-item">
          <a href="#">Terms of Use</a>
        </li>
      </ul>
    </div>
  </div>
</footer>
</div>
  </div>
</div>

CSS

html, body {
  height: 100%;
}
body {
  display: flex;
  flex-direction: column;
  background: #F1F3FA;
}
body { 
  overflow-x:hidden;
}
#mainNav {
  background-color: darkslategrey;
  color:white;
}
#mainNav .navbar-brand {
  color: #fed136;
  font-family: 'Kaushan Script', 'Helvetica Neue', Helvetica, Arial, cursive;
}


.content {
  flex: 1 0 auto;
}
.footer {
  flex-shrink: 0;
}


footer {
  text-align: center;
  background-color: white;
}
.ft{
  padding-left:22px;
  padding-right:31px;
}

footer span.copyright {
  font-size: 90%;
  line-height: 40px;
  text-transform: none;
  font-family: 'Montserrat', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color:blak;
}

footer ul.quicklinks {
  font-size: 90%;
  line-height: 40px;
  margin-bottom: 0;
  text-transform: none;
  font-family: 'Montserrat', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

ul.social-buttons {
  margin-bottom: 0;
}

ul.social-buttons li a {
  font-size: 20px;
  line-height: 40px;
  display: block;
  width: 40px;
  height: 40px;
  -webkit-transition: all 0.3s;
  -moz-transition: all 0.3s;
  transition: all 0.3s;
  color: white;
  border-radius: 100%;
  outline: none;
  background-color: #212529;
}

ul.social-buttons li a:active, ul.social-buttons li a:focus, ul.social-buttons li a:hover {
  background-color: #fed136;
}
.content{
   margin-top:60px;
 }


/* Profile container */
.profile {
  margin: 20px 0;
}

/* Profile sidebar */
.profile-sidebar {
  padding: 20px 0 10px 0;
  background: #fff;
}

.profile-userpic img {
  float: none;
  display:block;
    margin:auto;
  width: 50%;
  height: 50%;
  -webkit-border-radius: 50% !important;
  -moz-border-radius: 50% !important;
  border-radius: 50% !important;
}

.profile-usertitle {
  text-align: center;
  margin-top: 20px;
}

.profile-usertitle-name {
  color: #5a7391;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 7px;
}

.profile-usertitle-job {
  text-transform: uppercase;
  color: #5b9bd1;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 15px;
}

.profile-userbuttons {
  text-align: center;
  margin-top: 10px;
}

.profile-userbuttons .btn {
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 15px;
  margin-right: 5px;
}

.profile-userbuttons .btn:last-child {
  margin-right: 0px;
}
    
.profile-usermenu {
  margin-top: 30px;
}

.profile-usermenu ul li {
  border-bottom: 1px solid #f0f4f7;
}

.profile-usermenu ul li:last-child {
  border-bottom: none;
}

.profile-usermenu ul li a {
  color: #93a3b5;
  font-size: 14px;
  font-weight: 400;
}

.profile-usermenu ul li a i {
  margin-right: 8px;
  font-size: 14px;
}

.profile-usermenu ul li a:hover {
  background-color: #fafcfd;
  color: #5b9bd1;
}

.profile-usermenu ul li.active {
  border-bottom: none;
}

.profile-usermenu ul li.active a {
  color: #5b9bd1;
  background-color: #f6f9fb;
  border-left: 2px solid #5b9bd1;
  margin-left: -2px;
}

/* Profile Content */
.profile-content {
  padding: 20px;
  background: #fff;
  min-height: 460px;
}

.nav>li {
    position: relative;
    display: block;
}

Any help would be appreciated as I have tried multiple methods with no success.

Thank you in advance.

Upvotes: 2

Views: 533

Answers (2)

Nerevar.de
Nerevar.de

Reputation: 83

<div class="profile-sidebar position-fixed">

The position-fixed does not allow your profile-sidebar to move away.

It works otherwise https://jsfiddle.net/f9hot4yk/

Instead of adding the position fixed class you can add profile-sidebar into a min-width location in your CSS where you add the fixed property to the sidebar.

Like this:

@media only screen and (min-width: 1200px) {
  .profile-sidebar {
    position: fixed;
  }
}

Upvotes: 2

Giorgos Iordanidis
Giorgos Iordanidis

Reputation: 161

I see you have added a class position-fixed to the element with class profile-sidebar, so this element will remain fixed no matter what.

You could remove the class position-fixed and handle everything in the CSS, using media queries to set its position for smaller and larger screens.

Upvotes: 3

Related Questions