Javascript 当内容超过页面大小时,如何设置div可滚动?
我有下一页:Javascript 当内容超过页面大小时,如何设置div可滚动?,javascript,jquery,html,asp.net,css,Javascript,Jquery,Html,Asp.net,Css,我有下一页: <div id = "menu"> Menu on the left side </div> <div id = "header"> Header content of the page </div> <div id = "body"> Data Data Data Data Data Data Data </div> <div id = "footer"> Add
<div id = "menu">
Menu on the left side
</div>
<div id = "header">
Header content of the page
</div>
<div id = "body">
Data Data Data Data Data Data Data
</div>
<div id = "footer">
Additional Information
</div>
主体内部可以有不同的数据。我的问题是:
当正文内容超过用户页面时,我想修复除正文以外的所有div
。菜单应该在左侧,页眉应该在页面顶部,页脚应该在底部,只有正文应该是可滚动的
#header {
position: fixed;
top: 0;
display: inline-block;
width: 400px;
border-bottom: 1px solid rgb(238, 238, 238);
}
#footer {
position: fixed;
bottom: 0;
}
#menu {
position: fixed;
left: 0;
background: #244a7c;
padding: 7px 23px 0 7px;
width: 299px;
height: 1000px;
}
#body {
margin-left: 300px;
margin-top: <header-height>;
margin-bottom: <footer-height>;
}
请帮忙
谢谢 如果将
页眉
,页脚
和菜单
的位置设置为固定位置,并保持正文不变,则应能正常工作。只有正文可以滚动
#header {
position: fixed;
top: 0;
display: inline-block;
width: 400px;
border-bottom: 1px solid rgb(238, 238, 238);
}
#footer {
position: fixed;
bottom: 0;
}
#menu {
position: fixed;
left: 0;
background: #244a7c;
padding: 7px 23px 0 7px;
width: 299px;
height: 1000px;
}
#body {
margin-left: 300px;
margin-top: <header-height>;
margin-bottom: <footer-height>;
}
#头{
位置:固定;
排名:0;
显示:内联块;
宽度:400px;
边框底部:1px实心rgb(238238238238);
}
#页脚{
位置:固定;
底部:0;
}
#菜单{
位置:固定;
左:0;
背景:#244a7c;
填充:7px23px07px;
宽度:299px;
高度:1000px;
}
#正文{
左边距:300px;
页边空白处:;
页边距底部:;
}
这里有两个纯CSS解决方案
不固定任何高度(页眉/页脚)或宽度(左列)
实际上我更喜欢第二种解决方案。(即使他不太支持浏览器)
1-使用CSS技巧
这是一个完全响应的设计,适用于所有浏览器(IE10、FF、Chrome、Safari、Opera、移动浏览器)
HTML:
<div class="Container">
<div class="Header">
</div>
<div class="HeightTaker">
<div class="Wrapper Container Inverse">
<div>
<div class="Footer">
</div>
</div>
<div class="HeightTaker">
<div class="Wrapper">
<div class="LeftMenu">
</div>
<div class="Content">
</div>
</div>
</div>
</div>
</div>
</div>
*
{
margin: 0;
padding: 0;
}
html, body, .Container
{
height: 100%;
}
.Container:before
{
content: '';
height: 100%;
float: left;
}
.HeightTaker
{
position: relative;
z-index: 1;
}
.HeightTaker:after
{
content: '';
clear: both;
display: block;
}
.Wrapper
{
position: absolute;
width: 100%;
height: 100%;
}
.Inverse, .Inverse > *
{
-moz-transform: rotateX(180deg);
-ms-transform: rotateX(180deg);
-o-transform: rotate(180deg);
-webkit-transform: rotateX(180deg);
transform: rotateX(180deg);
}
.LeftMenu
{
height: 100%;
float: left;
}
.Content
{
overflow: auto;
height: 100%;
}
/*For demonstration only*/
p
{
font-size: 1.3em;
}
.Important
{
font-weight: bolder;
color: white;
}
body > .Container
{
text-align: center;
}
.Header
{
background-color: #bf5b5b;
}
.LeftMenu
{
background-color: #bdbe4c;
}
.Content
{
background-color: #90adc1;
}
.Footer
{
background-color: #b5a8b7;
}
*
{
margin: 0;
padding: 0;
}
html, body
{
height: 100%;
text-align: center;
}
body
{
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.Middle
{
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 0;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
overflow: hidden;
}
.Content
{
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 0 0;
overflow: auto;
}
/*For demonstration only*/
p
{
font-size: 1.3em;
}
.Important
{
font-weight: bolder;
color: white;
}
header
{
background-color: #bf5b5b;
}
.LeftMenu
{
background-color: #bdbe4c;
}
.Content
{
background-color: #90adc1;
}
footer
{
background-color: #b5a8b7;
}
2-使用Flex
这种布局也可以使用flex实现,但当前的浏览器支持是纯粹的。
这里有一个仅FF,Chrome,IE10
HTML:(更简单)
你能把代码放在一个文件夹里吗?你想要这样或这样的布局。你需要什么浏览器支持?我需要像1这样的布局,但还有一件事我需要它。若内容小于用户页面大小,则效果良好,但若内容大于页面大小,则我只需要可滚动的正文。
*
{
margin: 0;
padding: 0;
}
html, body
{
height: 100%;
text-align: center;
}
body
{
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.Middle
{
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 0;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
overflow: hidden;
}
.Content
{
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 0 0;
overflow: auto;
}
/*For demonstration only*/
p
{
font-size: 1.3em;
}
.Important
{
font-weight: bolder;
color: white;
}
header
{
background-color: #bf5b5b;
}
.LeftMenu
{
background-color: #bdbe4c;
}
.Content
{
background-color: #90adc1;
}
footer
{
background-color: #b5a8b7;
}