html - 只有一列可滚动的网格布局
问题描述
我想创建一个布局,其中左侧部分保持在同一个位置,只有右侧可以滚动。但是当我使用 position: fixed; 左侧部分变为视口的全宽和全高。
.container {
position: relative;
margin: 0;
padding: 0;
width: 100%;
display: grid;
grid-template-columns: 40% 60%;
}
.left {
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: red;
}
.right {
height: 200vh;
background-color: blue;
}
<div class="container">
<div class="left">
</div>
<div class="right">
</div>
</div>
解决方案
我创建了一个正确的内容,这会在右父 div 中溢出。
*{
margin: 0;
padding: 0;
}
.container {
position: relative;
margin: 0;
padding: 0;
width: 100%;
height: 100vh;
display: grid;
grid-template-columns: 40% 60%;
}
.left {
/*position: fixed;
top: 0;
left: 0;*/
/* height: 100%;
width: 100%;*/
background-color: red;
}
.right {
overflow-y: scroll;
height: 100vh;
background-color: blue;
}
.right_content{
height: 200vh
}
<div class="container">
<div class="left">
LEFT
</div>
<div class="right">
<div class="right_content">RIGHT</div>
</div>
</div>
推荐阅读
- javascript - Javascript 链接
- security - 谁在工作 SSL 提供商以及我如何创建 SSL/TLS 服务提供商,例如 certum 、 comodo 和 digicert
- ruby-on-rails - 在 Rails 查询中转义引号
- javascript - 在 JS 中具有编码挑战的一些方向/提示
- session - 我用的是django2.2.7内置的LoginView,首页模板和文章模板的request.user中获取的用户不一致
- git - 在 git 中创建具有多个项目的单个工作树
- reactjs - 如何从 GitLab 向其他人展示我的 React 应用程序?
- firebase - 是否可以在 Firebase Hosting 中独立于请求的 URL 重写 Cloud Function 调用结果?
- sql - 在 SQL 中组合 2 个表,包括不常见的字段
- python - 视差图只显示轮廓