我在这里有bootply,在右侧栏中,我在div中创建了一些面板。我试图获取它以便面板在列内滚动,但不是整个页面(我不希望页眉或页脚在面板的上方和下方滚动),但出于某种原因,& #39;溢出-y:滚动'是禁用还是不工作!
这是我的代码
html,body,.container {
height:calc(100% - 17px);
}
.container {
display:table;
width: 100%;
margin-top: -50px;
padding: 0px 0 0 0; /*set left/right padding according to needs*/
box-sizing: border-box;
}
.row {
height: 100%;
display: table-row;
}
.col-md-3 {
background: pink;
}
.col-md-9 {
background: yellow;
}
.row .no-float {
display: table-cell;
float: none;
}
header, footer {
text-align: center;
padding-top: 10px;
padding-bottom: 10px;
border-bottom: 1px solid lightgrey;
background: white;
}
footer {
border-top: 1px solid lightgrey;
position: absolute;
bottom: 0;
width: 100%;
}

<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<div class="row">
<div class="col-md-6 no-float">Navigation</div>
<div class="col-sm-6 no-float" style="padding-left: 0px; padding-right: 0px;">
<header>
<div class="btn-group btn-group-lg" role="group" aria-label="...">
<button type="button" class="btn btn-default">Events</button>
<button type="button" class="btn btn-default">Hosts</button>
<button type="button" class="btn btn-default">Teachers</button>
</div>
</header>
<div id="eventsContainer" style="overflow-y: scroll;">
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
</div>
<footer>
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-default">Events</button>
<button type="button" class="btn btn-default">Hosts</button>
<button type="button" class="btn btn-default">Teachers</button>
</div>
</footer>
</div>
</div>
</div>
&#13;
答案 0 :(得分:1)
您需要将height
分配给#eventsContainer
以使其滚动。所以使用CSS的calc()
函数。像:
#eventsContainer {
height: calc(100% - 122px); /* Total Height - Height of (header + footer) */
}
查看下面的工作代码段:
#eventsContainer {
height: calc(100% - 122px);
}
html,body,.container {
height:calc(100% - 17px);
}
.container {
display:table;
width: 100%;
margin-top: -50px;
padding: 0px 0 0 0; /*set left/right padding according to needs*/
box-sizing: border-box;
}
.row {
height: 100%;
display: table-row;
}
.col-md-3 {
background: pink;
}
.col-md-9 {
background: yellow;
}
.row .no-float {
display: table-cell;
float: none;
}
header, footer {
text-align: center;
padding-top: 10px;
padding-bottom: 10px;
border-bottom: 1px solid lightgrey;
background: white;
}
footer {
border-top: 1px solid lightgrey;
position: absolute;
bottom: 0;
width: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<div class="row">
<div class="col-md-6 no-float">Navigation</div>
<div class="col-sm-6 no-float" style="padding-left: 0px; padding-right: 0px;">
<header>
<div class="btn-group btn-group-lg" role="group" aria-label="...">
<button type="button" class="btn btn-default">Events</button>
<button type="button" class="btn btn-default">Hosts</button>
<button type="button" class="btn btn-default">Teachers</button>
</div>
</header>
<div id="eventsContainer" style="overflow-y: scroll;">
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
Basic panel example
</div>
</div>
</div>
<footer>
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-default">Events</button>
<button type="button" class="btn btn-default">Hosts</button>
<button type="button" class="btn btn-default">Teachers</button>
</div>
</footer>
</div>
</div>
</div>
希望这有帮助!
答案 1 :(得分:0)
问题是溢出仅在内容试图超过容器时才起作用。在您的示例中,#eventsContainer
没有设置高度,并且由于HTML的性质(垂直扩展以适应内容),内容正在推出。
为了实现滚动,您的#eventsContainer
必须有一个设定的高度。
然而,由于我假设您希望这个高度是动态的,而不是像'300px'那样静态的东西,我掀起了一个jsfiddle以展示绝对定位,以创建一个全屏版本,而无需向外推。