摘要:實現三欄布局,中間自適應負值法放第一行首尾高度固定中間自適應的布局兼容頭部中間置頂中間中間到底尾部針對設定的布局粘連置于底部方法一在上用負的粘連置于底部方法二在上用負的
實現三欄布局,中間自適應(margin負值法)
middle
left
right
body {
margin: 0;
padding: 0;
}
.left, .right {
height: 300px;
width: 200px;
float: left;
}
.right {
margin-left: -200px;
background-color: red;
}
.left {
margin-left: -100%;
background-color: #00ff00;
}
.middle {
height: 300px;
width: 100%;
float: left;
background-color: blue;
}
首尾高度固定、中間自適應的DIV布局(兼容IE6)
html, body {
margin: 0;
/*padding: 0;*/
height: 100%;
overflow: hidden;
}
.top, .bottom {
width: 100%;
height: 50px;
position: absolute;
}
/** {
margin: 0;
padding: 0;
}
html, body, .container {
height: 100%;
width: 100%;
}
div {
position: absolute;
}
.top, .bottom {
width: 100%;
height: 100px;
z-index: 5;
}*/
.top {
background: red;
top: 0;
}
.bottom {
background: #00ff00;
bottom: 0;
}
.middle {
width: 100%;
top: 50px;
bottom: 50px;
background: #a7fad7;
overflow: auto;
position: absolute;
/*針對ie6設定的hack*/
_height: 100%;
_border-top: -100px solid #eee;
_border-bottom: -100px solid #eee;
_top: 0;
}
flex-box布局
Main Content
I"m first in the source order.
The key to victory is discipline, and that means a well made bed. You will practice until you can make your
bed in your sleep. Fry, we have a crate to deliver. Hey, guess what you"re accessories to.
I"ll get my kit! That"s not soon enough! Oh, all right, I am. But if anything happens to me, tell them I died
robbing some old man.
Nav
body {
padding: 2em;
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
h1, h2 {
font: bold 2em Sans-serif;
margin: 0 0 1em 0;
}
h2 {
font-size: 1.5em;
}
p {
margin: 0 0 1em 0;
}
.page-wrap {
display: flex;
display: -webkit-flex;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
}
.main-content,
.main-sidebar,
.main-nav {
padding: 1em;
}
.main-content {
-webkit-box-ordinal-group: 2;
-moz-box-ordinal-group: 2;
-ms-flex-order: 2;
order: 2;
width: 60%;
-moz-box-flex: 1;
background: white;
}
.main-nav {
-webkit-box-ordinal-group: 1;
-moz-box-ordinal-group: 1;
-ms-flex-order: 1;
order: 1;
-webkit-box-flex: 1;
-moz-box-flex: 1;
width: 20%;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
background: #ccc;
}
.main-sidebar {
-webkit-box-ordinal-group: 3;
-moz-box-ordinal-group: 3;
-ms-flex-order: 3;
order: 3;
-webkit-box-flex: 1;
-moz-box-flex: 1;
width: 20%;
-ms-flex: 1;
-webkit-flex: 1;
flex: 1;
background: #ccc;
}
粘連 Footer 置于底部-方法一
HTML
在 wrapper 上用負的 margin-bottom
Add Content
CSS
html, body {
height: 100%;
margin: 0;
}
.content {
min-height: 100%;
padding: 20px;
margin: 0 auto -50px;
}
.footer,
.push {
height: 50px;
padding: 20px;
}
JS
$("#add").on("click", function () {
$("Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
").insertBefore(".push");
});
粘連 Footer 置于底部-方法二
HTML
在 footer 上用負的 margin-top
Add Content
CSS
html, body {
height: 100%;
margin: 0;
}
.content {
min-height: 100%;
}
.content-inside {
padding: 20px;
padding-bottom: 50px;
}
.footer {
height: 50px;
margin-top: -50px;
}
JS
$("#add").on("click", function () {
$("Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
").appendTo(".content-inside");
});
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/111828.html