您的位置:首页 > Web前端 > HTML

宽度固定的三栏布局

2016-08-05 16:27 393 查看
效果图



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 布局