Oll*_*y F 25 html css overflow
我有一个400px宽的DIV,它包含两个并排的DIV,每个DIV的宽度为400px,高度为600px.两个DIV的宽度是固定的,但高度可以变化.我想隐藏第二个DIV并完全显示第一个DIV,而DIV内部没有滚动.
我想,我的解决方案是隐藏溢出-x.这似乎也隐藏了y溢出.
这是我的代码:
#schools-sub-nav {
}
#schools-container {
width: 400px; /* Set the width of the visible portion of content here */
background-color: fuchsia;
position: relative;
overflow-x: hidden;
}
#schools-list {
width: 400px; /* Set the width of the visible portion of content here */
height: 600px; /* Delete the height, let the content define the height */
background-color: purple;
position: absolute;
top: 0;
left: 0;
}
#boards-list {
width: 400px; /* Set the width of the visible portion of content here */
height: 600px; /* Delete the height, let the content define the height */
background-color: green;
position: absolute;
top: 0;
left: 400px;
}Run Code Online (Sandbox Code Playgroud)
<div id="schools-sub-nav"> <a href="#schools-list">Schools List</a> // <a href="#boards-list">Boards List</a> </div>
<div id="schools-container">
<div id="schools-list"> One </div>
<div id="boards-list"> Two </div>
</div>Run Code Online (Sandbox Code Playgroud)
我希望#schools-list是可见的,但由于某种原因overflow-x: hidden在#schools-container隐藏它.
您使两个 div(具有绝对位置)的方式使溢出规则无效!
你需要改变位置类型(正常/非绝对),我建议使用浮动,最后,你想要应用溢出的容器div,需要有一种方法来适应它,比如在末尾放置一个div clear: both(在使用浮动的情况下)。
编辑:我刚刚尝试过,您可以按照上面的建议隐藏第二个 div,并在内部添加另一个宽度非常大的周围 div,并将主容器 div更改overflow-x为。overflow
像这样:
<div id="schools-container">
<div id="schools-container-inside">
<div id="schools-list"> One </div>
<div id="boards-list"> Two </div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
然后是CSS(我注释了原来未使用的CSS并在最后添加了新的div类):
#schools-container {
width: 400px; /* Set the width of the visible portion of content here */
background-color: fuchsia;
position: relative;
/*overflow-x: hidden;*/
overflow: hidden;
}
#schools-list {
width: 400px; /* Set the width of the visible portion of content here */
height: 600px; /* Delete the height, let the content define the height */
background-color: purple;
/*
position: absolute;
top: 0;
left: 0;
*/
float: left;
}
#boards-list {
width: 400px; /* Set the width of the visible portion of content here */
height: 600px; /* Delete the height, let the content define the height */
background-color: green;
/*
position: absolute;
top: 0;
left: 400px;
*/
float: left;
}
#schools-container-inside {
width: 10000px;
overflow: hidden;
}
Run Code Online (Sandbox Code Playgroud)
JsFiddle 在这里: http: //jsfiddle.net/MbMAc/
| 归档时间: |
|
| 查看次数: |
16231 次 |
| 最近记录: |