0

Codepen 在这里:https ://codepen.io/anon/pen/MvqWwg

我已经绝对定位了div.containerdiv.wrapper在里面。和两个 div 作为div.wrapper. 这些列有背景。

如何使这些背景到达最长列的末尾(即使它们具有相同的高度),而不仅仅是容器的可见高度?我无法position: absolute从中删除div.container

这是 HTML 代码:

<div class="container">
    <div class="wrapper">
        <div class="div1">
            <p>Some long content here</p>
            <p>Some long content here</p>
            <p>Some long content here</p>
            <p>Some long content here</p>
            <p>Some long content here</p>
            <p>Some long content here</p>
            <p>Some long content here</p>
            <p>Some long content here</p>
            <p>Some long content here</p>
        </div>
        <div class="div2">
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
            <p>Some even longer content here</p>
        </div>
    </div>
</div>

这是CSS:

.container {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    overflow: auto;
}
.wrapper {
    display: flex;
    align-items: stretch;
    width: 100%;
}
.div1 {
    background-color: yellow;
}
.div2 {
    flex: 1;
    background-color: green;
}
4

1 回答 1

3

删除container.

我也align-items: stretch; width: 100%;从 中删除了,.wrapper因为它是它们的默认值,不需要设置。

.container {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  /*  commented out these 2 lines
    display: flex;
    flex-direction: column;
  */
  overflow: auto;
}

.wrapper {
  min-height: 100%;
  display: flex;
  /*  commented out these 2 lines as they are not needed
    align-items: stretch;
    width: 100%;
  */
}

.div1 {
  background-color: yellow;
}

.div2 {
  flex: 1;
  background-color: green;
}

p {
  padding: 20px 10px;
}
<div class="container">
  <div class="wrapper">
    <div class="div1">
      <p>Some long content here</p>
      <p>Some long content here</p>
      <p>Some long content here</p>
    </div>
    <div class="div2">
      <p>Some even longer content here</p>
      <p>Some even longer content here</p>
      <p>Some even longer content here</p>
      <p>Some even longer content here</p>
      <p>Some even longer content here</p>
      <p>Some even longer content here</p>
      <p>Some even longer content here</p>
      <p>Some even longer content here</p>
    </div>
  </div>
</div>

于 2017-08-28T08:33:06.143 回答