越过窗口高度会增加元素宽度?

时间:2015-10-25 21:15:33

标签: html css html5

除了两个section元素外,我在页面上没有任何内容。 sections占用1280px width800px } height。当我将浏览器窗口width缩小到1281px时(使用Chrome的开发工具查看窗口的宽度),会出现一个水平滚动条,好像我缩小了width下面的1280px { 1}}。当我检查body元素时,它会在1264px中向我显示width。另一方面,开发工具向我显示窗口width1281px

当我将height元素的section降低到低于窗口当前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;
}

1 个答案:

答案 0 :(得分:0)

您可以使用以下方法删除水平滚动条:

 overflow: hidden;

这可能会阻止您遇到的问题。