限制弹性盒项目的高度[重复]

2023-11-27

我有一个包含 2 个项目的弹性盒,方向=行。第二项的文字内容很长。我希望第二个项目与第一个项目一样高,并且有一个滚动条。这可能吗?

#wrap { display: flex; }
#item-1 { height: 100px; background: orange; flex: 1; }
#item-2 { overflow: scroll; flex: 1; }
<div id='wrap'>
  <div id='item-1'></div>
  <div id='item-2'>  
I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br>
  </div>
</div>

我找到的最接近的帖子是这个吗,但答案似乎不适用于我的情况。


添加一个包装器position: absolute

现在,您可以设置min-height最左边的高度将跟随最右边的高度。

#wrap { display: flex; }
#item-1 { min-height: 100px; background: orange; flex: 1; }
#item-2 { position: relative; flex: 1; }
#item-wrap { 
  position: absolute; 
  left: 0; top: 0; 
  right: 0; bottom: 0;
  overflow: auto; 
}
<div id='wrap'>
  <div id='item-1'>
    If this gets longer, right most follows<br>
    If this gets longer, right most follows<br>
    If this gets longer, right most follows<br>
    If this gets longer, right most follows<br>
    If this gets longer, right most follows<br>
    If this gets longer, right most follows<br>
    If this gets longer, right most follows<br>
    If this gets longer, right most follows<br>
  </div>
  <div id='item-2'>  
  <div id='item-wrap'>  
I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br> I would like this text to have a scrollbar, and thus not take up more height than the orange box.<br>
  </div>
 </div>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

限制弹性盒项目的高度[重复] 的相关文章

  • Shift+Enter 按钮用于提交表单

    我想使用 Shift Enter 按钮提交表单 而不是简单地按 Enter 按钮 请帮助我 如果您仍然想这样做 尽管这会带来可用性问题 form keydown function e if e keyCode 13 e shiftKey W
  • 如何将 ng-repeat 分成批次

    我正在做这个 ref checkbox 示例http getbootstrap com javascript buttons examples http getbootstrap com javascript buttons example
  • 如何使用 CSS 绘制一个向左的三角形?

    我已经很久没有建造这个向上的三角形了 我怎样才能改变我的 CSS 使角指向左边 http jsfiddle net 3sP8q http jsfiddle net 3sP8q left corner width 0 height 0 bor
  • 检测滚动条是否可见(例如在移动设备上)

    我见过很多关于检测 HTML 元素是否可滚动的问题 答案 例如动态检测滚动条 https stackoverflow com questions 33805052 detect scrollbar dynamically 我需要类似的东西
  • PHP 邮件功能不发送任何消息[重复]

    这个问题在这里已经有答案了 我对问题所在感到困惑 在使用时没有收到任何电子邮件mailphp 函数 PHP HTML
  • 用于 Mysql 查询的 FLASK HTML 字段

    你好 Stackoverflow 社区 我是 FLASK 的新手 但是虽然学习曲线非常陡峭 但有一个项目我无法理解 我使用一个非常简单的 HTML 搜索表单 用户在其中输入城市名称 此输入将传递到 Mysql 查询并将输出返回到表中 一切正
  • 使用 Flexbox 时 Apex 图表无法正确调整大小

    最近 我将 Floats 更改为 FlexBox 以便更轻松地使用面板 正如我在其他问题上所建议的那样 虽然大多数事情都按我的预期工作 但更改后我在使用 Apex Charts 时遇到了问题 完整代码在这里 https github com
  • IE7内容可编辑自动换行

    我有以下代码 div class editable This is test text This is test text This is test text This is test text This is test text Thih
  • 我应该使用媒体查询来定位哪些设备/推荐尺寸?

    我是响应式网页设计的新手 并且感到困惑 因为对于使用哪些媒体查询以及要定位哪些设备有不同的偏好 有标准吗 我想定位 iPhone iPad 和其他流行设备 我在网上找到了这个 Smartphones portrait and landsca
  • 从 Django 基于类的视图的 form_valid 方法调用特殊(非 HTTP)URL

    如果你这样做的话 有一个 HTML 技巧 a href New SMS Message a 点击新短信打开手机的本机短信应用程序并预 先填写To包含所提供号码的字段 在本例中为 1 408 555 1212 以及body与提供的消息 Hel
  • 差异:查看页面源代码与在 Firebug 中查看

    当我查看页面的页面源时 例如 http my sa ucsb edu public curriculum coursesearch aspx http my sa ucsb edu public curriculum coursesearc
  • Sitecore 多种 RTE 类样式

    我可以为 RichTextEditor RTE 添加 CSS 样式路径 如下所示 并且我可以在 RTE 中选择定义的样式
  • 不透明动画在 IE 上不起作用

    我有一个动画菜单 其中包含一些级联不透明动画 这些动画在打开菜单和悬停每个按钮时执行 它只是每 100 毫秒向菜单上的每个图标添加 colorHigh 类 你可以看到一个现场演示在这里 http germanalvarez net 5 la
  • BEM 与 SASS 和 :hover

    使用 BEM 和 SASS 声明活动 焦点 悬停状态的正确方法是什么 例如 我有这样的结构 div class card img class card image src alt div class card overlay div cla
  • BS3 - img 响应类 - 为什么没有最大高度?

    引导程序 3 包括 img responsive班级 应用这些 css 设置 display block height auto max width 100 为什么没有max height 100 我发现添加这个使得图片的高度也适合 但我不
  • css 变换,chrome 中的锯齿状边缘

    我一直在使用 CSS3 转换来旋转网站中带有边框的图像和文本框 问题是 Chrome 中的边框看起来呈锯齿状 就像没有抗锯齿的 低分辨率 游戏一样 在 IE Opera 和 FF 中看起来好多了 因为使用了 AA 仍然清晰可见 但也没有那么
  • 不透明度如何影响元素顺序?

    我发现 CSS 有一个非常奇怪的行为opacity与浮动元素相结合 考虑以下 HTML div div Right button div div div Overlay div 最后div将覆盖前两个浮动的 删除不透明度会将最新的 div
  • Angular 中的动态子组件

    我正在构建一个具有一致的元素列表设计模式的应用程序 如果我有一个 A 类型的对象 我会创建AComponent它接受a作为输入 然后创建另一个组件来迭代 A 列表 AListComponent 那么如果我有一个对象 B 我需要做同样的事情
  • Bootstrap 响应式图像缩放

    Using Twitter Bootstrap我意识到默认情况下它会响应式地缩放图像 这很棒 但并不总是完美的 比如说我有一个500x300桌面上的图像 然后它会针对移动设备调整大小 该图像将非常小而且不是很高 会丢失图像的大部分细节部分
  • 管道符 (|) 和脱字符号 (^) 属性选择器有什么区别?

    At W3学校 http en wikipedia org wiki W3Schools他们声明两者 http www w3schools com cssref sel attribute value lang asp and http w

随机推荐