html - CSS : 只有一个 div 可滚动
问题描述
我试图让只有一个 div 可滚动,但我不知道该怎么做。
我希望 h2 和 c (黑色和蓝色)保持原样,只有 d (粉色)是可滚动的。
现在,整行都是可滚动的。
.a {
background-color:red;
width: calc(100vw - 3rem);
overflow:scroll;
}
.b {
background-color:green;
display: inline-flex;
height:3rem;
}
.c {
background-color:blue;
display: inline-flex;
width:3rem;
height:3rem;
}
.d {
background-color:pink;
display: inline-flex;
width:133rem;
height:3rem;
}
h2 {
background-color:black;
user-select: none;
font-weight:600;
font-size: 1.5rem;
height: 1.9rem;
width: 4.1rem;
margin-top: auto;
margin-bottom: auto;
height:3rem;
}
<div class='a'>
<div class='b'>
<h2></h2>
<div class='c'></div>
<div class='d'></div>
</div>
</div>
解决方案
用于position:fixed;
h2 和 for .c
useposition:fixed;left:4.1rem;
因为你的 h2 宽度是 4.1rem 所以使用 left:4.1rem
.a {
background-color:red;
width: calc(100vw - 3rem);
overflow:scroll;
}
.b {
background-color:green;
display: inline-flex;
height:3rem;
}
.c {
background-color:blue;
display: inline-flex;
width:3rem;
height:3rem;
position:fixed;
left:4.1rem;
}
.d {
background-color:pink;
display: inline-flex;
width:133rem;
height:3rem;
}
h2 {
background-color:black;
user-select: none;
font-weight:600;
font-size: 1.5rem;
height: 1.9rem;
width: 4.1rem;
margin-top: auto;
margin-bottom: auto;
height:3rem;
position:fixed;
left:0rem;
}
<div class='a'>
<div class='b'>
<h2></h2>
<div class='c'></div>
<div class='d'></div>
</div>
</div>
推荐阅读
- hyperledger - 没有来自任何同行的有效响应
- php - 权限被拒绝 Nginx Docker
- reactjs - 如何在渲染中显示此数组中的一项?
- amazon-web-services - 防止 AWS cloudformation 中的回滚
- javascript - 尽管在 vega-lite 教程中逐步执行,但遇到 TypeError
- .net - 如何在可以在项目中覆盖的库(NuGet 包)中进行默认设置?
- arrays - 修复致命错误:数组中的索引超出范围
- git - 我不明白带有子模块的 git pull
- matlab - 调试 MEX 文件 - 使用 -Dgdb 启动 MATLAB 不会产生 gdb 提示
- google-docs-api - 确定 Google Docs API 的状态?