网站标题在窗口大小调整时不会拉伸 100%
因此,我的网站 http://dealminion.com 的标头设置为 100%。但是,如果我调整浏览器窗口的大小然后向右滚动,标题会停止,但页面会继续前进。这很奇怪。如果您访问该网站并调整窗口大小,您就会看到我在说什么。 这是 css:
#header-intro {
width: 100%;
position: absolute;
height: 600px;
padding-top: 25px;
background-color: #657b90;
border-bottom: 1px solid #000000;
-moz-box-shadow: 0 5px 2px -2px #777777;
-webkit-box-shadow: 0 5px 2px -2px #777777;
box-shadow: 0 5px 2px -2px #777777;
behavior: url('pie.htc');
}
和正文 css:
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background: #f8f8f8;
}
发生这种情况有什么原因吗?
So my website http://dealminion.com has a header that is set to 100%. However if I resize the browser window then scroll to the right the header stops but the page keeps going. It's very odd. If you go to the site and resize the window you will see what I am saying.
Here is the css:
#header-intro {
width: 100%;
position: absolute;
height: 600px;
padding-top: 25px;
background-color: #657b90;
border-bottom: 1px solid #000000;
-moz-box-shadow: 0 5px 2px -2px #777777;
-webkit-box-shadow: 0 5px 2px -2px #777777;
box-shadow: 0 5px 2px -2px #777777;
behavior: url('pie.htc');
}
and the body css:
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background: #f8f8f8;
}
Is there any reason why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它会拉伸以包含具有
width: 100%
和padding: 10px
的#info
元素,从而有效地导致 20px 的内容溢出。由于
#info
是块级元素,因此不需要将宽度设置为100%。只需设置width: auto
(或者根本不设置),它将填充可用空间,留出内边距、边框和边距的余量,而不会导致溢出。更新:
我对您想要实现的目标有了更好的理解。
由于它是绝对定位的,因此宽度会折叠。不要为该元素显式设置宽度,而是使用
left
和right
隐式设置。It's stretching to contain your
#info
element which haswidth: 100%
andpadding: 10px
, effectively causing 20px of overflowed content.Since
#info
is a block-level element, you don't need to set the width to 100%. Just setwidth: auto
(or don't set it at all), and it will fill the available space, making allowances for padding, borders, and margins, without causing overflow.UPDATE:
I have a better understanding of what you're trying to accomplish.
Since it's absolutely positioned, the width collapses. Instead of setting your width explicitly for that element, set it implicitly with
left
andright
.如果您的
#info
中没有任何元素,请尝试:if you do not any element in your
#info
, try: