内容显示在导航栏下方,而不是右侧

时间:2019-11-01 18:15:52

标签: javascript html css navbar

此导航栏位于页面的左侧,添加到页面的新内容显示在导航栏的下方而不是右侧。我该如何解决这个问题?您可以在下面找到相关的HTML和CSS代码,以及两个显示我确切意思的图像。

我所拥有的与我想要的(我在第二张照片中使用了photoshop)

enter image description here enter image description here

body {
  overflow-x: hidden;
}

.sidebar {
  width: 260px;
  padding-top: 40px;
  padding-bottom: 0px;
  vertical-align: top;
  display: block;
  background-color: #292929;
  z-index: 100;
  height: 100%;
}

.sidebar a {
  display: block;
  padding: 20px 10px;
  border-top: 1px solid #161616;
}

.menu_sidebar {
  display: none;
  font-size: 20px;
}

.menu_sidebar li {
  padding: 10px;
  color: white;
  font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', sans-serif;
  font-size: 20px;
}

.main_sidebar {
  display: block;
  border-top: 1px solid #161616;
  flex-grow: 1;
  cursor: pointer;
}

.main_sidebar li {
  padding: 20px 10px;
  color: white;
  font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', sans-serif;
  font-size: 17px;
}

.main_sidebar li:hover {
  color: white;
  background: #292929;
  -o-transition: color .25s ease-out, background .25s ease-in;
  -ms-transition: color .25s ease-out, background .25s ease-in;
  -moz-transition: color .25s ease-out, background .25s ease-in;
  -webkit-transition: color .25s ease-out, background .25s ease-in;
  /* ...and now override with proper CSS property */
  transition: color .25s ease-out, background .25s ease-in;
  background-color: #232323;
}

.inner_sidebar a:active {
  border-right: 4px solid #1D3D54;
  width: 91%;
  background-color: #232323;
}

.inner_sidebar a {
  padding: 0px;
  height: 0;
  opacity: 0;
  border-top: 0px;
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.6s ease;
  pointer-events: none;
}

.inner_sidebar a.active {
  overflow: visible;
  opacity: 1;
  height: 18px;
  width: 92%;
  padding: 6px 10px;
  border-top: 0px;
  pointer-events: auto;
}

.inner_sidebar a li {
  color: white;
  font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', sans-serif;
  font-size: 12px;
}

.inner_sidebar a:hover {
  color: white;
  background: #292929;
  -o-transition: color .25s ease-out, background .25s ease-in;
  -ms-transition: color .25s ease-out, background .25s ease-in;
  -moz-transition: color .25s ease-out, background .25s ease-in;
  -webkit-transition: color .25s ease-out, background .25s ease-in;
  /* ...and now override with proper CSS property */
  transition: color .25s ease-out, background .25s ease-in;
  background-color: #232323;
}

.menu-close {
  float: right;
}

.chevron {
  float: right;
}


/* mobile */

.menu-toggle {
  color: white;
  float: left;
  padding: 10px 10px;
  font-size: 15px;
  cursor: pointer;
  display: none;
}

.menu-toggle li {
  vertical-align: middle;
  padding: 2.5px 0px;
}

.menu-toggle:hover {
  color: white;
  background: #292929;
  -o-transition: color .25s ease-out, background .25s ease-in;
  -ms-transition: color .25s ease-out, background .25s ease-in;
  -moz-transition: color .25s ease-out, background .25s ease-in;
  -webkit-transition: color .25s ease-out, background .25s ease-in;
  /* ...and now override with proper CSS property */
  transition: color .25s ease-out, background .25s ease-in;
  background-color: #185886;
}

@media (max-width: 1000px) {
  .menu-toggle {
    display: block;
  }
  .menu_sidebar {
    display: block;
  }
  .sidebar.active {
    left: 0;
  }
  .sidebar {
    position: absolute;
    width: 260px;
    background: #292929;
    top: 0px;
    left: -100%;
    transition: 0.5s;
    display: grid;
    padding-top: 0px;
    overflow-y: scroll;
    overflow-x: hidden;
  }
}
<main>
  <div class="sidebar" id="side-menu">
    <ul>
      <div class="menu_sidebar">
        <li>Menu<span class="menu-close"><i class="fa fa-times"></i></span></li>
      </div>
      <div class="main_sidebar">
        <li>Dashboard<span class="chevron"><i class="fa fa-chevron-down"></i></span></li>
      </div>
      <div class="inner_sidebar">
        <ul>
          <a href="#">
            <li>Option 1</li>
          </a>
          <a href="#">
            <li>Opt 2</li>
          </a>
          <a href="#">
            <li>Opt 3</li>
          </a>
          <a href="#">
            <li>Option 4</li>
          </a>
          <a href="#">
            <li>Opt 5</li>
          </a>
          <a href="#">
            <li>Opt 6</li>
          </a>
        </ul>
      </div>
      <div class="main_sidebar">
        <li>Stats<span class="chevron"><i class="fa fa-chevron-down"></i></span></li>
      </div>
      <div class="inner_sidebar">
        <ul>
          <a href="#">
            <li>Option 1</li>
          </a>
          <a href="#">
            <li>Opt 2</li>
          </a>
          <a href="#">
            <li>Opt 3</li>
          </a>
          <a href="#">
            <li>Option 4</li>
          </a>
          <a href="#">
            <li>Opt 5</li>
          </a>
          <a href="#">
            <li>Opt 6</li>
          </a>
        </ul>
      </div>
      <div class="main_sidebar">
        <li>Three<span class="chevron"><i class="fa fa-chevron-down"></i></span></li>
      </div>
      <div class="inner_sidebar">
        <ul>
          <a href="#">
            <li>Option 1</li>
          </a>
          <a href="#">
            <li>Opt 2</li>
          </a>
          <a href="#">
            <li>Opt 3</li>
          </a>
          <a href="#">
            <li>Option 4</li>
          </a>
          <a href="#">
            <li>Opt 5</li>
          </a>
          <a href="#">
            <li>Opt 6</li>
          </a>
        </ul>
      </div>
      <div class="main_sidebar">
        <li>Four<span class="chevron"><i class="fa fa-chevron-down"></i></span></li>
      </div>
      <div class="inner_sidebar">
        <ul>
          <a href="#">
            <li>Option 1</li>
          </a>
          <a href="#">
            <li>Opt 2</li>
          </a>
          <a href="#">
            <li>Opt 3</li>
          </a>
          <a href="#">
            <li>Option 4</li>
          </a>
          <a href="#">
            <li>Opt 5</li>
          </a>
          <a href="#">
            <li>Opt 6</li>
          </a>
        </ul>
      </div>
      <div class="main_sidebar">
        <li>Five<span class="chevron"><i class="fa fa-chevron-down"></i></span></li>
      </div>
      <div class="inner_sidebar">
        <ul>
          <a href="#">
            <li>Option 1</li>
          </a>
          <a href="#">
            <li>Opt 2</li>
          </a>
          <a href="#">
            <li>Opt 3</li>
          </a>
          <a href="#">
            <li>Option 4</li>
          </a>
          <a href="#">
            <li>Opt 5</li>
          </a>
          <a href="#">
            <li>Opt 6</li>
          </a>
        </ul>
      </div>
    </ul>
  </div>
  <div style="maincontent">
    <p style="color: black;">test content</p>
    <p style="color: black;">test content</p>
    <p style="color: black;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: white;">test content</p>
    <p style="color: black;">test content</p>
    <p style="color: black;">test content</p>
  </div>
</main>

1 个答案:

答案 0 :(得分:1)

定位包装主容器并设置为flex添加到您的css主容器{display:flex;}