【问题标题】:Why doesnt my nav align with other two columns?为什么我的导航不与其他两列对齐?
【发布时间】:2021-08-29 06:46:17
【问题描述】:

我正在尝试创建 3 列,其中导航在左侧,文章在中间,然后是旁边。

但现在它似乎忽略了我的导航,而我的“文章”div 在它后面而不是在它旁边。这是为什么呢?

仅当页面处于“大模式”且未缩小时才会发生。

这就是我想要实现的目标

*, html {
    margin:0;
    padding:0;
}


 /* The sidenav */
.sidenav {
  height: 100%;
  width: 200px;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: #111;
  overflow-x: hidden;
  padding-top: 20px;
}

/* Page content */
.main {
  margin-left: 200px; /* Same as the width of the sidenav */
} 
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
        integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
        integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
        crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
        integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
        integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
        crossorigin="anonymous"></script>


</head>

<body>
    <div class="container-fluid h-100">
        <div class="row h-100">
            <div class="sidenav col-lg-1 col-sm-12 order-sm-2 order-lg-1 ">
                <a href="#">About</a>
                <a href="#">Services</a>
                <a href="#">Clients</a>
                <a href="#">Contact</a>
            </div>

            <div class="bg-warning col-lg-10 col-sm-12 order-sm-1 order-lg-2">
                <p>Article</p>
            </div>

            <div class="bg-primary col-lg-1 col-sm-12 order-sm-3 order-lg-3">
                <p>Aside</p>
            </div>
        </div>
    </div>
</body>



</html>

【问题讨论】:

  • sn-p 似乎没有重现问题?
  • 全屏拉起来就可以了
  • 我试过全屏。你在使用一些古老的浏览器吗?
  • 我明白你的意思,这很奇怪,我使用的是最新版本的 Firefox,运行 sn-p 时,它看起来与我电脑上的不同,即使我复制粘贴它。
  • 这是我机器上的样子i.imgur.com/W6fDANU.png

标签: html css twitter-bootstrap bootstrap-4 twitter-bootstrap-3


【解决方案1】:

您没有在 HTML 中使用 CSS 中的 .main 类。您应该将内容(sidenav 除外)包装在使用它的 div 中。

【讨论】:

    【解决方案2】:

    *,
    html {
      margin: 0;
      padding: 0;
    }
    
    
    /* The sidenav */
    
    .sidenav {
      height: 100%;
      width: 200px;
      position: fixed;
      z-index: 1;
      top: 0;
      left: 0;
      background-color: #111;
      overflow-x: hidden;
      padding-top: 20px;
    }
    
    
    /* Page content */
    
    .main {
      margin-left: 200px;
      width: 400px;
      height: 100%;
      /* Same as the width of the sidenav */
    }
    
    .main2 {
    height: 100%;
    width: 100px;
    }
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
      <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
      <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    
    
    </head>
    
    <body>
        <div class="container-fluid h-100">
           <div class="row h-100">
            <div class="sidenav">
              <a href="#">About</a>
              <a href="#">Services</a>
              <a href="#">Clients</a>
              <a href="#">Contact</a>
            </div>
            <div class="main">
              <div class="bg-warning col-lg-10 col-sm-12 order-sm-1 order-lg-2">
                <p>Article</p>
              </div>
              </div>
              <div class="main2">
              <div class="bg-primary col-lg-1 col-sm-12 order-sm-3 order-lg-3">
                <p>Aside</p>
            </div>
            </div> 
            </div>
          </div> 
    </body>
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2019-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多