关于圣杯布局,想问一下容器里面的overflow:hidden;有什么用?
关于圣杯布局,想问一下容器里面的overflow:hidden;有什么用?我注意到取消了这一句后在IE7的浏览器上左侧的部分显示不出来?是什么原因?
.container{
padding:0 220px 0 200px;
overflow: hidden;
}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>圣杯布局</title>
<style type="text/css">
*{margin: 0;padding: 0;}
body{min-width: 700px;}
.header,
.footer{
border: 1px solid #333;
background: #ddd;
text-align: center;
height: 40px;
line-height: 40px;
}
.left,
.middle,
.right{
position: relative;
float: left;
min-height: 130px;
}
.container{
padding:0 220px 0 200px;
overflow: hidden;
}
.left{
margin-left: -100%;
left: -200px;
width: 200px;
background: #f00;
}
.right{
margin-left: -220px;
right: -220px;
width: 220px;
background: #30a457;
}
.middle{
width: 100%;
background: #1a5acd;
word-break: break-all;
}
.footer{
clear: both;
}
</style>
</head>
<body>
<div class="header">
<h4>header</h4>
</div>
<div class="container">
<div class="middle">
<h4>middle</h4>
<p>
这是页面的主体内容
这是页面的主体内容
这是页面的主体内容
这是页面的主体内容
这是页面的主体内容
这是页面的主体内容
这是页面的主体内容
这是页面的主体内容
</p>
</div>
<div class="left">
<h4>left</h4>
<p>
这是页面的左边
这是页面的左边
这是页面的左边
这是页面的左边
这是页面的左边
这是页面的左边
</p>
</div>
<div class="right">
<h4>right</h4>
<p>
这是页面的右边
这是页面的右边
这是页面的右边
这是页面的右边
</p>
</div>
</div>
<div class="footer">
<h4>footer</h4>
</div>
</body>
</html>21
收起
正在回答 回答被采纳积分+1
4回答
慕用4150088
2018-02-27 09:08:22
我的代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
html,body {
padding: 0;
margin: 0;
}
body {
min-width: 620px;
}
.header,.footer {
background-color: #999;
text-align: center;
overflow: hidden;
}
.main {
padding: 0 220px 0 200px;
/* 这个我所知道的有两个作用:1清除浮动,2、解决IE7的兼容问题*/
overflow: hidden;
text-align: center;
}
.left,
.center,
.right {
position: relative;
float: left;
}
.center {
width: 100%;
background: pink;
}
.left {
width: 200px;
background-color: yellow;
margin-left: -100%;
left: -200px;
}
.right {
width: 220px;
background-color: green;
margin-left: -220px;
right: -220px;
}
</style>
</head>
<body>
<div class="header">
<h1>header</h1>
</div>
<div class="main">
<div class="center">
<h1>center</h1>
<p>这是中间部分</p>
</div>
<div class="left">
<h1>left</h1>
<p>这是左侧部分</p>
</div>
<div class="right">
<h1>right</h1>
<p>这是右侧部分</p>
</div>
</div>
<div class="footer">
<h1>footer</h1>
</div>
</body>
</html>
好帮手慕糖
2018-02-26 19:05:31
你好,如下,图一是顶部的宽度,这个是正常页面的宽度,图二是主体部分的宽度,可以发现比实际的宽度要宽。可以测试查看下,这里也不是左边部分也不是消失了,而是在屏幕部分还有朝左的位置中,所以整体的宽度会显示有点宽,建议:可以把left元素的margin-left: -100%;值稍微调小点,例:-80%左右,是可以看到左边部分的。
图一:
图二:
这里跟文档声明也有一定的影响,可换为doctype 声明类型,发现宽度就可以正常。如下图:
图三:
图四:
ie 盒子模型的范围包括 margin、border、padding、content,和标准 w3c 盒子模型不同的是:ie 盒子模型的 content 部分包含了 border 和 pading。建议:可了简单解下ie盒子模型与标准盒子模型的区别来进行理解。
祝学习愉快~
前端小白入门系列课程
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星