【发布时间】:2015-10-25 21:15:33
【问题描述】:
页面上除了两个 section 元素之外什么都没有。 sections 都占用了 width 的 1280px 和 height 的 800px。当我将浏览器窗口width 缩小到1281px(使用Chrome 的开发工具查看窗口宽度)时,会出现一个水平滚动条,就好像我将width 缩小到1280px 以下一样。当我检查body 元素时,它告诉我它是width 中的1264px。另一方面,开发工具显示窗口width 是1281px。
当我将两个section 元素的height 减小到低于窗口当前height 的值时,例如300px,水平滚动条消失并且body width 显示成为1281px。
我也在页面上应用了css reset。
是什么原因造成的,如何预防?
section#sec1{
background: orange;
}
section#sec2{
background: pink;
}
section{
display: block;
margin:0px auto;
width:1280px;
height:800px;
}
<section id="sec1">Some content</section>
<section id="sec2">Other content</section>
如果你想要 jsfiddle:https://jsfiddle.net/L991shcp/
然后重置:
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
【问题讨论】:
-
请发布您的所有 CSS(例如,您使用什么重置?)。更好的是,你能创建一个 jsfiddle 吗?很明显,问题出在您发布的 CSS/HTML 之外,但除非我们能看到,否则无法说出是什么。