0
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>MY NAME</title>
        <style>
        /*CSS RESET*/
        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;
    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 RESET*/
body
{
    background-color: white;
    width: 100vw;
    max-width: 100vw;
}


header
{
    width: 100vw;
    max-width: 100vw;

    height: 15vh;

    max-height: 8vw;
    background-color: white;
}

h1
{
    font-size: 5vw;
    max-height: 5vw;
    line-height: 1;
    color: #333333;
}

h2
{
    font-size: 2vw;
    max-height: 2vw;
    line-height: 0.1;
    color: #333333;
}

#upperContainer
{
    width: 100vw;
    max-width: 100vw;
    max-height: 60vh;
    background-color: purple;
    text-align: center;


}

#leftBlock
{
    width: 50vw;
    height: 60vh;
    max-width: 100vw;
    max-height: 60vh;
    height: 60vh;
    display: inline-block;
    vertical-align: middle;
    background-color: pink;

}

#rightBlock
{
    width: 50vw;
    max-height: 60vh;
    background-color: yellow;
    display: inline-block;
    vertical-align: middle;
}

#lowerContainer
{
    width: 100vw;
    max-width: 100vw;
    max-height: 60vh;
    background-color: purple;
    text-align: center;
}

#leftBlock2
{
    width: 50vw;
    height: 60vh;
    max-width: 100vw;
    max-height: 60vh;
    height: 60vh;
    display: inline-block;
    vertical-align: middle;
    background-color: green;

}

#rightBlock2
{
    width: 50vw;
    height: 60vh;
    max-height: 60vh;
    background-color: yellow;
    display: inline-block;
    vertical-align: middle;
}

footer
{
    width: 100vw;
    max-width: 100vw;
    height: 15vh;
    max-height: 8vw;
    background-color: blue;
}
        </style>
    </head>
    <body>
            <header>
                <mark><h1>MY NAME</h1></mark>
                <h2>DESCRIPTION</h2>
            </header> 

            <section id="upperContainer"><article id="leftBlock"></article><article id="rightBlock"></article></section>
            <!--UNCOMMENT TO SEE PROBLEM <section id="lowerContainer"><article id="leftBlock2"></article><article id="rightBlock2"></article></section>-->

    <footer>FOOTER</footer>
    </body>
</html>

My question is: when i remove the comment tags "" in the html.. suddenly the width of the page is wider than the browser window. Do you guys have any idea how to fix this ? I feel like its some kind of weird error.

blabla
  • 3
  • 3

3 Answers3

1

Here is updated JsFiddle https://jsfiddle.net/4erj4w2p/1/. The problem is your width units - vw (viewport width). It takes into account scrollbar width as well. Please refer to this : Why does vw include the scrollbar as part of the viewport?

Updated Css:

/*CSS RESET*/
        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;
    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 RESET*/
body
{
    background-color: white;
    width: 100%;
    max-width: 100%;
}


header
{
    width: 100%;
    max-width: 100%;

    height: 15vh;

    max-height: 8vw;
    background-color: white;
}

h1
{
    font-size: 5vw;
    max-height: 5vw;
    line-height: 1;
    color: #333333;
}

h2
{
    font-size: 2vw;
    max-height: 2vw;
    line-height: 0.1;
    color: #333333;
}

#upperContainer
{
    width: 100%;
    max-width: 100vw;
    max-height: 60vh;
    background-color: purple;
    text-align: center;


}

#leftBlock
{
    width: 50%;
    height: 60vh;
    max-width: 100vw;
    max-height: 60vh;
    height: 60vh;
    display: inline-block;
    vertical-align: middle;
    background-color: pink;

}

#rightBlock
{
    width: 50%;
    max-height: 60vh;
    background-color: yellow;
    display: inline-block;
    vertical-align: middle;
}

#lowerContainer
{
    width: 100%;
    max-width: 100vw;
    max-height: 60vh;
    background-color: purple;
    text-align: center;
}

#leftBlock2
{
    width: 50%;
    height: 60vh;
    max-width: 100vw;
    max-height: 60vh;
    height: 60vh;
    display: inline-block;
    vertical-align: middle;
    background-color: green;

}

#rightBlock2
{
    width: 50%;
    height: 60vh;
    max-height: 60vh;
    background-color: yellow;
    display: inline-block;
    vertical-align: middle;
}

footer
{
    width: 100%;
    max-width: 100vw;
    height: 15vh;
    max-height: 8vw;
    background-color: blue;
}
Community
  • 1
  • 1
Mahesh Chavda
  • 593
  • 3
  • 9
0

First, you have no height in your #rightBlock.. add this:

height: 60vh;

Then, when you add your second section, lowerContainer, you "automatically" creates a vertical scrollbar. Because of your scrollbar, you need more horizontal space to show your content, and that is because your have your horizontal scrollbar.

If you put height = 10vh instead, you won't have any problem.

Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
  • Thank you ! You guys are such heroes ! Stuff like this can really freak me out.. thanks again. – blabla May 16 '16 at 18:08
0

This is giving extra width because of the 100vw. I updated 100vw with 100% and it is working fine. Please check by updating it.

Also can you please tell me about vw? Is it anything related with px. or just a locale issue??

Bkjain655
  • 200
  • 6
  • Uhm.. i have ben using vw and vh( viewport width and viewport height) for some time now and always used to think it was perfect for responsive design. -> http://www.w3schools.com/cssref/tryit.asp?filename=trycss_unit_vw – blabla May 16 '16 at 18:06