English 中文(简体)
如何将弹性项目延伸到超流量-开发集装箱以外?
原标题:How to extend a flex item beyond an overflow-scroll container?

我有一个可以简化的内容:

* {
  margin: 0;
}

.container {
  height: 400px;
}

.content {
  display: flex;
  flex-direction: column;
  height: 100%
}

.top {
  height: 48px;
  background-color: blue;
}

.bottom {
  flex: 1;
  display: flex;
  overflow-y: scroll;
}

.main {
  display: flex;
  flex: 1;
  background: green;
  position: relative;
  align-items: stretch;
}

.sidebar {
  width: 100px;
  background-color: yellow;
  border: 1px solid orange;
  min-height: 100%;
}

.sidebar-item {
  height: 300px;
  border: 1px solid purple;
}

.flex-item {
  flex: 1;
  border: 1px solid red;
}
<div class="container">
  <div class="content">
    <div class="top"></div>
    <div class="bottom">
      <div class="sidebar">
        <div class="sidebar-item"></div>
        <div class="sidebar-item"></div>
        <div class="sidebar-item"></div>
      </div>
      <div class="main">
        <div class="flex-item"></div>
        <div class="flex-item"></div>
        <div class="flex-item"></div>
      </div>
    </div>
  </div>
</div>

问题是,旁边bar被拖拉,而弹性物品的高度是超量部分,而不是超出部分。

如何确定这一点?

我尝试使用<代码>align-items: limit/code>,但未作任何改动。 我也试图把身高到不同的因素,但没有工作。

问题回答

您可将<代码>.bottom改为网布,并指定<代码>-auto-rows: min-content。 这样,集装箱内容的高度取决于其内容,而不是集装箱本身:

.bottom {
  flex: 1;
  display: grid;
  overflow-y: scroll;
  grid-auto-flow: column;
  grid-template-columns: auto;
  grid-auto-rows: min-content;
  grid-auto-columns: 1fr;
}

* {
  margin: 0;
}

.container {
  height: 400px;
}

.content {
  display: flex;
  flex-direction: column;
  height: 100%
}

.top {
  height: 48px;
  background-color: blue;
}

.bottom {
  flex: 1;
  display: grid;
  overflow-y: scroll;
  grid-auto-flow: column;
  grid-template-columns: auto;
  grid-auto-rows: min-content;
  grid-auto-columns: 1fr;
}

.main {
  display: flex;
  flex: 1;
  background: green;
  position: relative;
  align-items: stretch;
}

.sidebar {
  width: 100px;
  background-color: yellow;
  border: 1px solid orange;
  min-height: 100%;
}

.sidebar-item {
  height: 300px;
  border: 1px solid purple;
}

.flex-item {
  flex: 1;
  border: 1px solid red;
}
<div class="container">
  <div class="content">
    <div class="top"></div>
    <div class="bottom">
      <div class="sidebar">
        <div class="sidebar-item"></div>
        <div class="sidebar-item"></div>
        <div class="sidebar-item"></div>
      </div>
      <div class="main">
        <div class="flex-item"></div>
        <div class="flex-item"></div>
        <div class="flex-item"></div>
      </div>
    </div>
  </div>
</div>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签