0

I have nothing on the page except two section elements. Both the sections take up 1280px of width and 800px of height. When I shrink the browser window width down to 1281px (using Chrome's Dev tool to see the window's width), a horizontal scroll bar appears as if I had shrank the windows width below 1280px. When I inspect the body element it shows me that it is 1264px in width. On the other hand, Dev Tool shows me that the window width is 1281px.

When I decrease the height of both the section elements to a value lower than the window's current height, for example 300px, the horizontal scroll bar disappears and the body width is shown to be 1281px.

I have also applied css reset on the page as well.

what is causing this and how to prevent this?

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>

If you want jsfiddle: https://jsfiddle.net/L991shcp/

and the reset:

/* 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;
}
Tanaka
  • 23
  • 1
  • 6
  • Please post all of your CSS (what reset are you using for example?). Even better, can you create a jsfiddle? Clearly the problem is something other than the CSS/HTML you have posted, but it is impossible to say what unless we can see it. – Josef Engelfrost Oct 25 '15 at 21:20
  • Possible duplicate of [Difference between $(window).width() vs $(document).width()](http://stackoverflow.com/questions/9431050/difference-between-window-width-vs-document-width) – Szabolcs Páll Oct 25 '15 at 21:20

1 Answers1

0

You can remove the horizontal scroll bar using:

 overflow: hidden;

This might prevent the issue you are facing.

Florin Pop
  • 5,105
  • 3
  • 25
  • 58
  • This does not explain why the horizontal scrolling is happening (which is very difficult when the question is lacking information). – Josef Engelfrost Oct 25 '15 at 21:21