宽度固定的三栏布局
2016-08-05 16:27
393 查看
效果图
![](https://img-blog.csdn.net/20160805162424709?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="wrapper">
<header>
<h1>Fixed-Width Layout</h1>
</header>
<nav>
<div class="inner">
<ul>
<li>link1</li>
<li>link2</li>
<li>link3</li>
</ul>
</div>
</nav>
<article>
<div clas="inner">
A telephone was ringing in the darkness—a tinny, unfamiliar ring.<br />
He fumbled for the bedside lamp and turned it on.<br />
Squinting at his surroundings he saw a plush Renaissance bedroom with Louis XVI furniture,
hand-frescoed walls, and a colossal mahogany four-poster bed.
A telephone was ringing in the darkness—a tinny, unfamiliar ring.<br />
He fumbled for the bedside lamp and turned it on.<br />
Squinting at his surroundings he saw a plush Renaissance bedroom with Louis XVI furniture,
hand-frescoed walls, and a colossal mahogany four-poster bed.
A telephone was ringing in the darkness—a tinny, unfamiliar ring.<br />
He fumbled for the bedside lamp and turned it on.<br />
Squinting at his surroundings he saw a plush Renaissance bedroom with Louis XVI furniture,
hand-frescoed walls, and a colossal mahogany four-poster bed.
</div>
</article>
<aside>
<div class="inner">
<h2>This is aside</h2>
He fumbled for the bedside lamp and turned it on.<br />
Squinting at his surroundings he saw a plush Renaissance.
</div>
</aside>
<footer>this is footer</footer>
</div>
</body>
</html>
css样式
*{
margin: 0;
padding: 0;
}
#wrapper{
/*overflow: hidden;*/
width: 960px;
margin: 0 atuo;
border: 1px solid;
}
article{
box-sizing: border-box;/*第三种方法*/
background: #ffed53;
width: 600px;
float: left;
padding: 10px;
}
nav{
box-sizing: border-box;/*第三种方法*/
width:150px ;
float: left;
background: #dcd9c0;
}
nav li{
list-style-type: none;
}
aside{
box-sizing: border-box;/*第三种方法*/
width:210px;
float: left;
background: #3f7ccf;
}
header{
background: #f00;
text-align: center;
}
footer{
background: #DCD9C0;
clear: both;
text-align: center;
}
/*.inner{
padding:10px;
}*/
笔记:中间article栏增加padding和margin时,会造成右边的aside栏跑到下面,有两种解决办法。
1.给中间的内容增加一个div,改变这儿div的padding和margin
2.给三个块元素增加box-sizing:border-box
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="wrapper">
<header>
<h1>Fixed-Width Layout</h1>
</header>
<nav>
<div class="inner">
<ul>
<li>link1</li>
<li>link2</li>
<li>link3</li>
</ul>
</div>
</nav>
<article>
<div clas="inner">
A telephone was ringing in the darkness—a tinny, unfamiliar ring.<br />
He fumbled for the bedside lamp and turned it on.<br />
Squinting at his surroundings he saw a plush Renaissance bedroom with Louis XVI furniture,
hand-frescoed walls, and a colossal mahogany four-poster bed.
A telephone was ringing in the darkness—a tinny, unfamiliar ring.<br />
He fumbled for the bedside lamp and turned it on.<br />
Squinting at his surroundings he saw a plush Renaissance bedroom with Louis XVI furniture,
hand-frescoed walls, and a colossal mahogany four-poster bed.
A telephone was ringing in the darkness—a tinny, unfamiliar ring.<br />
He fumbled for the bedside lamp and turned it on.<br />
Squinting at his surroundings he saw a plush Renaissance bedroom with Louis XVI furniture,
hand-frescoed walls, and a colossal mahogany four-poster bed.
</div>
</article>
<aside>
<div class="inner">
<h2>This is aside</h2>
He fumbled for the bedside lamp and turned it on.<br />
Squinting at his surroundings he saw a plush Renaissance.
</div>
</aside>
<footer>this is footer</footer>
</div>
</body>
</html>
css样式
*{
margin: 0;
padding: 0;
}
#wrapper{
/*overflow: hidden;*/
width: 960px;
margin: 0 atuo;
border: 1px solid;
}
article{
box-sizing: border-box;/*第三种方法*/
background: #ffed53;
width: 600px;
float: left;
padding: 10px;
}
nav{
box-sizing: border-box;/*第三种方法*/
width:150px ;
float: left;
background: #dcd9c0;
}
nav li{
list-style-type: none;
}
aside{
box-sizing: border-box;/*第三种方法*/
width:210px;
float: left;
background: #3f7ccf;
}
header{
background: #f00;
text-align: center;
}
footer{
background: #DCD9C0;
clear: both;
text-align: center;
}
/*.inner{
padding:10px;
}*/
笔记:中间article栏增加padding和margin时,会造成右边的aside栏跑到下面,有两种解决办法。
1.给中间的内容增加一个div,改变这儿div的padding和margin
2.给三个块元素增加box-sizing:border-box
相关文章推荐
- CSS三栏布局(两边固定中间自适应宽度)的方法
- CSS三栏布局(两边固定中间自适应宽度)的方法
- 前端经典面试题之CSS实现三栏布局,左右宽度固定,中间宽度自适应
- CSS三栏布局——中间固定两边自适应宽度
- CSS三栏布局探讨——中间固定宽度两边自适应宽度
- CSS三栏布局——中间固定两边自适应宽度
- CSS实现左右栏宽度固定中间栏宽度变化且各栏高度自适应背景色不同的三栏布局
- 三栏布局方案:左右宽度固定,自适应布局
- CSS三栏布局(两边固定中间自适应宽度)的方法
- 用两种不同的方式来实现一个三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化
- CSS布局中左(右)宽度自适应,右(左)宽度固定
- 流式布局&固定宽度&响应式&rem
- 百分比和固定宽度的混合布局
- CSS 圣杯布局升级版---多个固定宽度一个自适应宽度
- div固定宽度左右布局【zt】
- CSS布局:中栏固定宽度,左右两栏宽度自适应
- 框架布局,用Frameset如何实现固定宽度的居中
- 固定右栏宽度, 左栏内容先出现同时自适应宽度的布局
- 用两种不同的方法来实现一个两列布局,其中左侧部分宽度固定、右侧部分宽度随浏览器宽度的变化而自适应变化
- 阿里2016前端开发工程师笔试 - 布局之左侧自动宽度右侧固定宽度