我在一个div中有一个div,但是第二个div并不是从父div的顶部开始的,它是由一个头部向下分流的。第二个div包含许多内容,需要滚动,所以我将其设置为100%高度并允许溢出;但是,因为它不是从父div的顶部开始的,所以它延伸到父div的底部。
下面是一个代码片段
html, body {
height: 100%;
overflow:hidden;
margin:0;padding:0
}
.profile-box {width: 46.6%; /*max-width: 560px;*/ height: 35%; max-height:600px; background-color:white; margin:1.6%; padding-top: 0.8%; padding-left: 0.8%; padding-right: 0.8%;}
.profile-form {margin-right:5; margin-left:auto; padding-right:3%;}
.profile-slider {width:45%}
.profile-slider-label {margin-right:1%}
.left-align {float:left;}
.right-align {float:right;}
.y-scolling {overflow-y:auto; overflow-x:hidden; height:100%;}<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="profile-box right-align" style="background-color:red">
<h2>Lifestyle</h2>
<p class="left-align">Scroll for more</p>
<div class="form-horizontal" style="background-color:grey">
<div class="y-scolling" style="background-color:yellow">
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div><div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<div class="form-group profile-form">
<input runat="server" class="profile-slider right-align" type="range" min="1" max="10" step="1" id="cat1" />
<label class="control-label right-align profile-slider-label" for="cat1">Cat1</label>
</div>
<!-- more of these -->
</div>
</div>
</div>
</body>


发布于 2015-02-13 00:52:51
尝试将overflow: scroll;添加到该div的css中。
示例:
div.someClass {
overflow: scroll;
}您也可以尝试其他溢出属性。但是从图片上看,你想让它在div中滚动。overflow:隐藏也可能是一种选择。
https://stackoverflow.com/questions/28483108
复制相似问题