【问题标题】:Flexbox CSS Overflow Div Content is Expanding DivFlexbox CSS 溢出 Div 内容正在扩展 Div
【发布时间】:2022-12-07 16:03:50
【问题描述】:

我正在设计一个应用程序的样式。我在这里做了一个模拟布局:https://codepen.io/Sean713/pen/VwdgMEx?editors=1100

我的代码也将粘贴在底部。

一切都按照我想要的方式工作,除了当绿色 div 内容过多时(您可以取消注释 p 标签),它会增加所有 div 的大小。我不希望这些 div 改变大小,而我只想将绿色 div 中的内容压缩到可滚动部分,我该如何解决这个问题?

 <ul>
   <li><a>Solve</a></li>
   <li><a>About</a></li>
   <li><a>Other</a></li>
</ul>

<div class="yellow">
  
  <div class="blue">
    <div class="darkgrey">
      This is the top left half
    </div>
    <div class="lightgrey">
      This is the top right half
    </div>
  </div>
  
  <div class="red">
    <div class="green">
      <p>I can scroll</p>
      <p>I can scroll</p>
      <p>I can scroll</p>
<!--       <p>I can scroll</p>
      <p>I can scroll</p>
      <p>I can scroll</p>
      <p>I can scroll</p>
      <p>I can scroll</p>
      <p>I can scroll</p>
      <p>I can scroll</p>
      <p>I can scroll</p>
      <p>I can scroll</p> -->

    </div>
  </div>
  
</div>
body {
  margin: 0;
  padding: 10px;
  background-color: white;
  
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.yellow {
  background-color: yellow;
  padding: 10px;
  
  flex: 1; /* should occupy the entire screen except the navbar */
  display: flex; /* should create flex for blue and red */
  flex-direction: column;
}

.blue {
  background-color: blue;
  flex: 2; /* should take up 2/3rds of yellow */
  display: flex; /* should create flex for the top left and top right halves */
  min-height: 240px;
  padding: 10px;
}

.red {
  background-color: red;
  padding: 15px;
  
  flex: 1; /* should take up 1/3rd of yellow */
  display: flex; /* should create flex for green, so that green can expand to fill it */
  flex-direction: column;
  min-height: 120px;
  
}

.green {
  background-color: green;
  overflow: scroll;
  
  flex: 1; /* should fill the entire red */
}

.darkgrey {
  background-color: darkgrey;
  flex: 1; /* will fill half the width of blue */
}

.lightgrey {
  background-color: lightgrey;
  flex: 1; /* will fill half the width of blue */
}

/*  navbar stuff */
ul {
  list-style-type: none;
  display: flex;
  align-items: center;
  margin: 0;
  box-sizing: border-box;
}

/*  navbar stuff */
li a {
  display: block;
  text-align: center;
  padding: 15px 15px;
  text-decoration: none;
}

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    显示:柔性;

    <div class="flex-container">
    
    1个 2个 3`在这里输入代码`

    【讨论】:

    • 嗨 Deeptimaan,非常感谢您的回答。你能进一步解释一下吗?我真的不明白。这段代码在做什么,我应该把它放在哪里?
    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 2013-05-01
    • 2017-09-25
    相关资源
    最近更新 更多