|
|
1
Rahul
8 年前
这很容易使用
Bootstrap@4
或使用
flex-box
CSS
. 使用检查代码段
Bootstrap@4
.
body{
height: 100%;
width: 100%;
}
.main-wrapper{
background-color: #f5f5f5;
height: 100%;
left: 0;
padding-bottom: 50px;
padding-top: 50px;
position: fixed;
top: 0;
width: 100%;
}
@media (max-width: 991px){
.main-wrapper{
overflow-x: hidden;
overflow-y: auto;
}
}
.header-wrapper{
background-color: #009688;
color: white;
height: 50px;
width: 100%;
}
.footer-wrapper{
background-color: #121212;
color: white;
height: 50px;
width: 100%;
}
.body-wrapper{
background-color: #f0f0f0;
width: 100%;
}
.content-1{
background-color: #2DC050;
color: white;
padding: 30px;
width: 100%;
}
.content-2{
background-color: #1FA325;
color: white;
padding: 30px;
width: 100%;
}
@media (min-width: 992px){
.content-1,
.content-2{
overflow-x: hidden;
overflow-y: auto;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<div class="main-wrapper d-flex flex-row">
<div class="header-wrapper fixed-top d-flex flex-row align-items-center justify-content-center">
I'm fixed header. I will be alwase visible on top. I'm fixed height.
</div>
<div class="body-wrapper d-flex flex-row flex-wrap">
<div class="col-12 col-lg-6 d-flex flex-row pl-0 pr-0">
<div class="content-1 d-flex flex-column text-center">
<h1>I'm content One. My position is left. I'm alwase fit with any browser window except header and footer height. Also I'm scrollable if content isn't fit.</h1>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
</div>
</div>
<div class="col-12 col-lg-6 d-flex flex-row pl-0 pr-0">
<div class="content-2 d-flex flex-column">
<h1>I'm content Two. My position is right. I'm alwase fit with any browser window except header and footer height. Also I'm scrollable if content isn't fit.</h1>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
</div>
</div>
</div>
<div class="footer-wrapper fixed-bottom d-flex flex-row align-items-center justify-content-center">
I'm fixed footer. I will be alwase visible on bottom. I'm fixed height.
</div>
</div>
-
始终使用页眉和页脚
fixed
.
-
内容1和内容2将
scroll-able
if浏览器
min-width
是
992px
.
-
整个页面将
可滚动
if浏览器
max-width
是
991px
.
编辑用于
Ronaldo
评论
. 答案是肯定的,这是可能的。检查底部代码段。
body{
height: 100%;
width: 100%;
}
.main-wrapper{
background-color: #f5f5f5;
height: 100%;
left: 0;
padding-bottom: 50px;
padding-top: 50px;
position: fixed;
top: 0;
width: 100%;
}
.header-wrapper{
background-color: #009688;
color: white;
height: 50px;
width: 100%;
}
.footer-wrapper{
background-color: #121212;
color: white;
height: 50px;
width: 100%;
}
.body-wrapper{
background-color: #f0f0f0;
width: 100%;
}
@media (max-width: 991px){
.body-wrapper{
overflow-x: hidden;
overflow-y: auto;
}
}
.content-1{
background-color: #2DC050;
color: white;
padding: 30px;
width: 100%;
}
.content-2{
background-color: #1FA325;
color: white;
min-height: 700px;
padding: 30px;
width: 100%;
}
@media (min-width: 992px){
.content-1{
overflow-x: hidden;
overflow-y: auto;
}
}
.content-2-1{
background-color: #0D420F;
padding: 20px;
width: 100%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<div class="header-wrapper fixed-top d-flex flex-row align-items-center justify-content-center">
I'm fixed header. I will be alwase visible on top. I'm fixed height.
</div>
<div class="main-wrapper d-flex flex-row">
<div class="body-wrapper d-flex flex-row flex-wrap">
<div class="col-12 col-lg-6 d-flex flex-row pl-0 pr-0">
<div class="content-1 d-flex flex-column text-center">
<h1>I'm content One. My position is left. I'm alwase fit with any browser window except header and footer height. Also I'm scrollable if content isn't fit.</h1>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
</div>
</div>
<div class="col-12 col-lg-6 d-flex flex-row pl-0 pr-0">
<div class="content-2 d-flex flex-row">
<div class="content-2-1 d-flex flex-column align-items-center justify-content-center text-center">
I'm Content 2 child element. My parent content-2 background color name is Forest Green. My background color is Myrtle. My width and height is 100%. I follow my parent height.
</div>
</div>
</div>
</div>
</div>
<div class="footer-wrapper fixed-bottom d-flex flex-row align-items-center justify-content-center">
I'm fixed footer. I will be alwase visible on bottom. I'm fixed height.
</div>
-
新代码段包括
html
结构已更改。
-
去除
page scroll
从…起
.main-wrapper
class
并添加到
body-wrapper
班
.
-
如果需要
child
盒
100%
width
和
height
然后
parent
应该是
display: flex;
flex-direction: row;
和
小孩
盒
应该是
width: 100%; // width can be changed if it multiple
小孩
box.
检查
.content-2
和
.content-2-1
CSS
密码
注意:所有代码段都将签入完整页面视图,并调整浏览器窗口的大小以检查移动响应。
|