我想滚动显示内容区域而不是页面。
根据documentation,我应该可以通过应用引导程序overflow-auto
类来做到这一点,但是我无法正常工作,例如,此处的黄色div;
* {
padding: 1em;
}
html,
body {
margin: 0;
padding: 0;
background-color: #0F0;
}
nav {
background-color: #F00;
}
main {
background-color: #FFF;
}
.header {
background-color: #07f;
}
.content {
background-color: #f7f;
}
.scroll {
background-color: #FD0;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container p-0">
<div class="row p-0">
<nav class="col-md-2">Nav bar</nav>
<main class="col-md-10">
<div class="header">
<b>Header</b>
</div>
<div class="content">
<b>Title</b>
<div class="scroll overflow-auto">
<div class="E">1</div>
<div class="E">2</div>
<div class="E">3</div>
<div class="E">4</div>
<div class="E">5</div>
<div class="E">6</div>
<div class="E">7</div>
<div class="E">8</div>
<div class="E">9</div>
<div class="E">10</div>
<div class="E">11</div>
<div class="E">12</div>
<div class="E">10</div>
<div class="E">11</div>
<div class="E">12</div>
<div class="E">10</div>
<div class="E">11</div>
<!--<div class="E">12</div>-->
</div>
</div>
</main>
</div>
</div>
</body>
答案 0 :(得分:2)
要添加滚动,必须定义内容的高度(如注释中所述)。您可以使用overflow
定义overflow-y
y轴,并使用overflow
定义overflow-x
x轴。或者,您可以使用overflow:auto
将两个轴都设置为溢出。
工作代码:
* {
padding: 1em;
}
html,
body {
margin: 0;
padding: 0;
background-color: #0F0;
}
nav {
background-color: #F00;
}
main {
background-color: #FFF;
}
.header {
background-color: #07f;
}
.content {
background-color: #f7f;
}
.scroll {
background-color: #FD0;
height: 200px;
overflow-y: auto;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container p-0">
<div class="row p-0">
<nav class="col-md-2">Nav bar</nav>
<main class="col-md-10">
<div class="header">
<b>Header</b>
</div>
<div class="content">
<b>Title</b>
<div class="scroll overflow-auto">
<div class="E">1</div>
<div class="E">2</div>
<div class="E">3</div>
<div class="E">4</div>
<div class="E">5</div>
<div class="E">6</div>
<div class="E">7</div>
<div class="E">8</div>
<div class="E">9</div>
<div class="E">10</div>
<div class="E">11</div>
<div class="E">12</div>
<div class="E">10</div>
<div class="E">11</div>
<div class="E">12</div>
<div class="E">10</div>
<div class="E">11</div>
<!--<div class="E">12</div>-->
</div>
</div>
</main>
</div>
</div>
</body>