代码之家  ›  专栏  ›  技术社区  ›  Mohammad Vard

如何设置车身的全高线条

  •  1
  • Mohammad Vard  · 技术社区  · 9 月前

    我网站的主体没有特定的高度,所以我找不到它的确切大小。我想显示一条从上到下的线,如下所示:

    .lines {
      height: 100%;
      position: absolute;
      background-color: #000;
      height: 100%;
      width: 20px;
      position: absolute;
      right: 50%;
      top:0;
    }
    
    
    .div1 {
      background-color: red;
      width: 500px;
      height: 500px;
    }
    
    .div2 {
      margin-top: 20px;
      background-color: blue;
      width: 500px;
      height: 500px;
    }
    <body>
      <div class="lines">
    
      </div>
      <div class="div1">
    
      </div>
      <div class="div2">
    
      </div>
    
    </body>

    但我找不到我身体的确切高度。和 height: 100%; 只需填写网站的一部分。

    3 回复  |  直到 9 月前
        1
  •  2
  •   Andy    9 月前

    改变 .lines position: fixed

    该元素将从正常文档流中删除,并且不会在页面布局中为该元素创建任何空间。元素相对于其初始包含块进行定位。其最终位置由顶部、右侧、底部和左侧的值决定。

    .lines {
      position: fixed;
      height: 100%;
      background-color: #000;
      width: 20px;
      right: 50%;
      top:0;
    }
    
    
    .div1 {
      background-color: red;
      width: 500px;
      height: 500px;
    }
    
    .div2 {
      margin-top: 20px;
      background-color: blue;
      width: 500px;
      height: 500px;
    }
    <body>
      <div class="lines"></div>
      <div class="div1"></div>
      <div class="div2"></div>
    </body>
        2
  •  0
  •   Joerie    9 月前

    看看 this post

    我建议使用 height: 100vh;

        3
  •  0
  •   Sunny Parsana    9 月前

    body{position:relative; width:100%; height:100%; margin:0px;}
    .lines {
      height: 100%;
      position: absolute;
      background-color: #000;
      height: 100vh;
      width: 20px;
      position: absolute;
      right: 50%;
      top:0;
    }
    
    
    .div1 {
      background-color: red;
      width: 500px;
      height: 50vh;
    }
    
    .div2 {
      margin-top: 0px;
      background-color: blue;
      width: 500px;
      height: 50vh;
    }
    <body>
      <div class="lines">
    
      </div>
      <div class="div1">
    
      </div>
      <div class="div2">
    
      </div>
    
    </body>