【问题标题】:Wanting height of two objects to match in spite of expanding content尽管内容扩展,但希望两个对象的高度匹配
【发布时间】:2016-06-21 14:21:30
【问题描述】:

我的页面包含三个主要部分:

  • 项目箭头框
  • 白-绿
  • 浅灰色

project-arrow-boxlight-gray 位于页面左侧,white-green 位于右侧。我希望light-graywhite-green 的底部在同一点相遇并触摸我的页脚。我的white-green 的部分将根据验证错误或任何情况改变大小。在不同的屏幕尺寸上,这两个 div(light-graywhite-green)非常合适。有时light-gray 会超过white-green,反之亦然。同样,无论屏幕大小如何,我都希望这两个 div 的末尾/底部触摸我的页脚。

我尝试将bottom: 0; 添加到light-graywhite-green,但这没有帮助。我将white-green 的高度设置为自动,因此它适应了这个 div 的扩展性质。这发生在页脚之前,因此页脚与这些问题无关。

我该怎么做才能让这成为可能?

.project_arrow_box {
  position: relative;
  /*background: rgb(69,186,149);*/
  background: #00a16d;
  border: 4px solid #00a16d;
  width: 33%;
  height: 800px;
  z-index: 99;
}

#project-content-wrap {
  margin: 30% 13%;
}

.white-green {
  background-color: rgb(241, 250, 247);
  width: 66.56%;
  height: auto;
  z-index: 55;
  margin-left: 33.4%;
  margin-right: 0;
  position: absolute;
  top: 0;
  right: 0;
  text-align: center;
}

#white-green-section {
  position: relative;
  left: 30%;
  text-align: center;
  opacity: 0;
}

.light-gray {
  background-color: #E0E0E0;
  width: 33.5%;
  padding-top: 150px;
  bottom: 0;
  margin-bottom: 0;
}

.light-gray-container {
  left: 15%;
  position: relative;
  width: 80%;
  height: auto;
  padding-bottom: 40px;
}
<div class="project_arrow_box">
  <div id="project-content-wrap">
  </div>
</div>
<div class="white-green">
    <div id="white-green-section">
    </div>
</div>
<div class="light-gray">
    <div class="light-gray-container">
    </div>
</div>

【问题讨论】:

    标签: html css position height


    【解决方案1】:

    使用 Flexbox 可能是实现这一目标的最简单方法:

    HTML:

    <div class="container">
      <div class="left-container">
        <div class="project-arrow-box">
          <p>
    
          </p>
        </div>
        <div class="light-grey">
          <p>
    
          </p>
        </div>
      </div>
      <div class="white-green">
        <p>
    
        </p>
      </div>
    </div>
    <div class="footer">
      <p>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos, vero?
      </p>
    </div>
    

    CSS:

    .container, .left-container, .white-green {
      display: -webkit-box;  /* OLD - iOS 6-, Safari 3.1-6, BB7 */
      display: -ms-flexbox;  /* TWEENER - IE 10 */
      display: -webkit-flex; /* NEW - Safari 6.1+. iOS 7.1+, BB10 */
      display: flex;         /* NEW, Spec - Firefox, Chrome, Opera */
      margin: 0;
    }
    
    .left-container {
      display: -webkit-box; 
      display: -ms-flexbox;  
      display: -webkit-flex; 
      display: flex;         
      flex-direction: column;
    }
    
    .project-arrow-box {
      background-color: white;
      flex-grow: 1;
      padding: 1em;
    }
    
    .light-grey {
      background-color: #aaa;
      flex-grow: 1;
      padding: 1em;
    }
    
    .white-green {
      background-color: #ccFFcc;
      flex-grow: 1;
      padding: 1em;
    }
    
    .footer {
      background-color: #000;
      color: #fff;
    }
    

    见:https://jsfiddle.net/bL2ymhps/1/

    【讨论】:

      【解决方案2】:

      您可以通过Flexbox 做到这一点

      body, html {
        margin: 0;
        padding: 0;
      }
      
      .container {
        display: flex;
      }
      
      .left {
        display: flex;
        flex-direction: column;
        flex: 0 0 33%;
      }
      
      .one {
        background: #A1EB88;
        flex: 100vh;
      }
      
      .two {
        flex: 100vh;
        background: #F2BB7C;
      }
      
      .three {
        background: lightblue;
        flex: 1;
      }
      
      footer {
        height: 50px;
        background: red;
        width: 100%;
      }
      <div class="container">
        <div class="left">
          <div class="one">One</div>
          <div class="two">Two</div>
        </div>
        <div class="three">Three</div>
      </div>
      <footer>Footer</footer>

      【讨论】:

      • flex: 1;.three 类中是什么意思?
      • 这意味着它将占用.left div 之后剩余的剩余宽度,因为33% 因为这个flex: 0 0 33%; 你可以在这里看到jsfiddle.net/Lg0wyt9u/156 如果你这样做,就会发生这种情况更改为flex: 0 0 70%;
      • flex: 0 0 33%; 证明了什么?明明是 33% 的屏幕,但是这两个零是干什么用的?顶部和底部?
      • 第一个零表示不增长,第二个不收缩,33% 是基础。你可以在这里阅读更多内容developer.mozilla.org/en-US/docs/Web/CSS/flex。和这个jsfiddle.net/Lg0wyt9u/158一样
      • 出于某种原因我的white-green div(你的3号)不会一直到页脚?这里是真实页面optimumwebdesigns.com/discuss-project
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      • 2021-02-08
      • 1970-01-01
      • 2020-07-16
      • 2020-03-14
      • 2015-06-30
      相关资源
      最近更新 更多