html - flex box如何使子级溢出保持垂直对齐
问题描述
我有 2 个孩子的弹性盒子。两者都垂直对齐。第二个孩子有一个头衔。这应该是静态的。当有更多项目时,list-items
旁边的应该是可滚动的。
目前我添加了一个高度来list-items
获取滚动条。但我仍然不知道要应用的确切高度。list-items
当flex 孩子中有更多内容时,使其可滚动的正确方法是什么?
这是我的演示:
.parent{
display: flex;
border: 1px solid red;
height: 20rem;
align-items: center;
}
p{
border: 1px solid black;
}
.drop{
background-color: beige;
flex: 1;
}
.list{
background-color: lightblue;
width: 20rem;
}
.list-items{
overflow-y: auto;
height: 18rem;
}
<div class="parent">
<div class="drop">
drop item
</div>
<div class="list">
<h4>Title goes here </h4>
<div class="list-items">
<p>List items goes here </p>
<p>List items goes here </p>
<p>List items goes here </p>
<p>List items goes here </p>
<p>List items goes here </p>
<p>List items goes here </p>
<p>List items goes here </p>
<p>List items goes here </p>
<p>List items goes here </p>
<p>List items goes here </p>
</div>
</div>
</div>
解决方案
推荐阅读
- javascript - 如何根据传递给css的变量值应用字体大小属性
- java - Spring Data JPA Rollback If Save Method Throw Exception
- android - 在 GeoCoder 地址中获取 maxAddressLineIndex 的大小 0
- react-native - 我需要创建一个多语言聊天机器人,用 dialogFlow 做出本机反应
- vba - 在 word 2016 中启用/禁用内容控制文本框
- html - 如何使细节标记居中?
- ruby-on-rails - 我可以安全地告诉 Rails 记住一个昂贵的实例方法的结果吗?
- xamarin - 在 Xamarin Forms 中隐藏导航栏
- excel - 每周重复的提醒消息,直到用户执行操作
- prestashop - 首页 prestashop 一直加载没有结果?