三列浮动固定布局
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>3 column layout</title>
<style>
aside, article, section, header, footer, nav {
display: block;
}
html, body {
margin: 0;
padding: 0;
}
html {
background: rgb(123, 121, 143);
}
body {
width: 960px;
background: #fff;
margin: 0 auto 2em;
font: 100% Georgia, "Times New Roman", Times, serif;
}
header {
background: rgb(76, 67, 65);
margin-bottom: 20px;
}
header h1 {
font: normal 2em Arial, Helvetica, sans-serif;
color: white;
text-align: center;
line-height: 4em;
text-transform: uppercase;
letter-spacing:.1em;
margin: 0;
}
.col1 {
background: rgb(237, 228, 214);
height: 500px;
float:left;
width:300px;
}
.col2 {
background: rgb(219,126,64);
height: 500px;
width:300px;
margin-left:330px;
}
.col3 {
background: rgb(173, 169, 130);
height: 500px;
width:300px;
margin-left:660px;
}
footer {
background: rgb(100, 98, 102);
line-height: 3em;
font-size: .6em;
color: white;
padding: 0 2em;
clear: both;
}
</style>
</head>
<body>
<header>
<h1>Cool company header</h1>
</header>
<section class="col1">
This is where the really important stuff goes.
</section>
<section class="col2">
This is where equally important stuff goes.
</section>
<aside class="col3">
This is where the related content goes.
</aside>
<footer>Copyright stuff....</footer>
</body>
</html>
要么
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>3 column layout</title>
<style>
aside, article, section, header, footer, nav {
display: block;
margin:0;
padding:0;
}
html, body {
margin: 0;
padding: 0;
}
html {
background: rgb(123, 121, 143);
}
body {
width: 960px;
background: #fff;
margin: 0 auto 2em;
font: 100% Georgia, "Times New Roman", Times, serif;
}
header {
background: rgb(76, 67, 65);
margin-bottom: 20px;
}
header h1 {
font: normal 2em Arial, Helvetica, sans-serif;
color: white;
text-align: center;
line-height: 4em;
text-transform: uppercase;
letter-spacing:.1em;
margin: 0;
}
.col1 {
background: rgb(237, 228, 214);
height: 500px;
float:left;
width:300px;
margin-right:30px;
}
.col2 {
background: rgb(219,126,64);
height: 500px;
width:300px;
margin-right:20px;
}
.col3 {
background: rgb(173, 169, 130);
height: 500px;
width:300px;
}
footer {
background: rgb(100, 98, 102);
line-height: 3em;
font-size: .6em;
color: white;
padding: 0 2em;
clear: both;
}
section {
display:inline-block;
}
aside {
display:inline-block;
}
</style>
</head>
<body>
<header>
<h1>Cool company header</h1>
</header>
<section class="col1">
This is where the really important stuff goes.
</section>
<section class="col2">
This is where equally important stuff goes.
</section>
<aside class="col3">
This is where the related content goes.
</aside>
<footer>Copyright stuff....</footer>
</body>
</html>
我有一个960像素的身体宽度,因此我将它划分为3栏,每栏300px X 3,总计900px,边距30px X 2 b / w两栏总共60px.All合计为960px。
现在我已经给出了第一列宽度为300px,并使用了浮动属性,所以第二个盒子在它旁边对齐,所以我已经给出了一个330px的边距,这是20px,所以我完成了工作。所以我有一个空间剩下约330px对,我给第三个框的边距为660px,宽度为20px,宽度为300px。
我想第三个盒子坐在第二个不在发生的地方,而不是第二个线路,我知道我可以使用float-left两个第二个盒子或使用一个float到第三个盒子。我想知道为什么这个方法不是努力工作是他们的空间。
在第二部分中,我已经在一旁使用了部分内联块,即使这样它仍然可行,但问题是,我已经在消耗900px [300X3 = 900]的所有三个盒子上使用了300像素,当我使用“我的身体”宽度为960像素右边缘为30px和30px,第三个框移动到第二个线,但是当我使用30px和20px时,它仍然是为什么?
很简单,您还没有将column2浮动到左侧,因此它包含在普通文档流程中。 因此,它获取整个块空间并将其下面的第三列移动。 你所需要做的就是
.col2 {
background: rgb(219,126,64);
height: 500px;
width:300px;
float: left;
margin-left:30px;
}
请检查这一个http://jsfiddle.net/966naq5e/17/我改变了一点点结构和更新
aside, article, section, header, footer, nav {
display: block;
margin:0;
padding:0;
}
*{
box-sizing: border-box
}
html, body {
margin: 0;
padding: 0;
}
html {
background: rgb(123, 121, 143);
}
body {
width: 960px;
background: #fff;
margin: 0 auto 2em;
font: 100% Georgia, "Times New Roman", Times, serif;
}
header {
background: rgb(76, 67, 65);
margin-bottom: 20px;
}
header h1 {
font: normal 2em Arial, Helvetica, sans-serif;
color: white;
text-align: center;
line-height: 4em;
text-transform: uppercase;
letter-spacing:.1em;
margin: 0;
}
.col1 .content{
background: rgb(237, 228, 214);
height: 500px;
}
.col2 .content{
background: rgb(219,126,64);
height: 500px;
}
.col3 .content{
background: rgb(173, 169, 130);
height: 500px;
}
footer {
background: rgb(100, 98, 102);
line-height: 3em;
font-size: .6em;
color: white;
padding: 0 2em;
clear: both;
}
section {
display:inline-block;
}
aside {
display:inline-block;
}
.container{
width: 960px;
margin: 0 auto;
}
.holder{
margin: 0 -15px;
overflow: hidden;
}
.holder .col{
width: 330px;
padding: 0 15px;
float: left;
}
<div class="container">
<div class="holder">
<section class="col1 col">
<div class="content">
This is where the really important stuff goes.
</div>
</section>
<section class="col2 col">
<div class="content">This is where equally important stuff goes.</div>
</section>
<aside class="col3 col">
<div class="content"> This is where the related content goes.</div>
</aside>
</div>
</div>
<footer>Copyright stuff....</footer>
链接地址: http://www.djcxy.com/p/13179.html