[html] Make div 100% Width of Browser Window

I'm trying to make one of my containers 100% of the width of the screen.

Here is my SASS

body, html { 
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}

#neo_wrapper {  
    width: 960px;
    height: 1500px;
    margin: 0 auto;

    #neo_main_container1 {  /* Slide1 container */
        width: 100%;
        height: 100%;
        margin: 0 auto;
        background: #999999;
        z-index: 350;

        #neo_scroll_button {    /* Div that enables scroll */
            position: absolute;
            bottom: 35px;
            left: 0;
            right: 0;
            margin: 0 auto;
            width: 150px;
            height: 15px;
            background: #F00;
            color: #FFF;
            text-align: center;
            line-height: 15px;
            display: table; 

            a { 
                &:link {text-decoration: none; color: #FFF;}
                &:visited {text-decoration: none; color: #FFF;}
            }
       }
    }

     #neo_main_container2 {
        width: 100%;
        height: 100%;
        margin: 0 auto;
        background: #CCC;
        z-index: 300;

        #neo_img_container {
           float: left;
           width: 350px;
           height: 500px;
            margin: 0 auto;
            margin-right: 15px;
         }

        #neo_text_container {
            float: left;
            width: 50%;
            height: 500px;
            margin: 0 auto;
        }
    }
 }

And HTML

<body>
<div id="neo_wrapper">
    <div id="neo_main_container1">  <!-- Start container1 -->
        <div id="neo_scroll_button" onClick="scrollBelow()">
            <p>Enter</p>
        </div>
    </div>  <!-- End of container1 -->
    <div id="neo_main_container2">  <!-- Start container2 -->
        <div id="neo_img_container">
            <img src="http://fpoimagery.com/?t=px&w=350&h=250&bg=0ff&fg=000000" />
        </div>
        <div id="neo_text_container">
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
        </div>
    </div>  <!-- End container2 -->
</div>

I want #neo_main_container1 to be the full width of the screen. Obviously because it's a child of #neo_wrapper, setting width to 100% will make it 960px. I'm sure how to circumvent this issue, so any help would be appreciated.

Updated: Here is my JS fiddle: http://jsfiddle.net/VkqjH/

This question is related to html css sass fullscreen

The answer is


.myDiv {
    background-color: red;
    width: 100%;
    min-height: 100vh;
    max-height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0 auto;
}

Basically, we're fixing the div's position regardless of it's parent, and then position it using margin: 0 auto; and settings its position at the top left corner.


If width:100% works in any cases, just use that, otherwise you can use vw in this case which is relative to 1% of the width of the viewport.

That means if you want to cover off the width, just use 100vw.

Look at the image I draw for you here:

enter image description here

Try the snippet I created for you as below:

_x000D_
_x000D_
.full-width {_x000D_
  width: 100vw;_x000D_
  height: 100px;_x000D_
  margin-bottom: 40px;_x000D_
  background-color: red;_x000D_
}_x000D_
_x000D_
.one-vw-width {_x000D_
  width: 1vw;_x000D_
  height: 100px;_x000D_
  background-color: red;_x000D_
}
_x000D_
<div class="full-width"></div>_x000D_
<div class="one-vw-width"></div>
_x000D_
_x000D_
_x000D_


Try to give it a postion: absolute;


Set the margin for body at 0 and that will fix it.

body {
   margin: 0;
}

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to sass

Error: Node Sass version 5.0.0 is incompatible with ^4.0.0 How to fix ReferenceError: primordials is not defined in node Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` What is the difference between CSS and SCSS? Angular-cli from css to scss Why don’t my SVG images scale using the CSS "width" property? Angular CLI SASS options Error: Cannot find module 'gulp-sass' How to compile or convert sass / scss to css with node-sass (no Ruby)? Try reinstalling `node-sass` on node 0.12?

Examples related to fullscreen

Make div 100% Width of Browser Window How to show imageView full screen on imageView click? Embed youtube videos that play in fullscreen automatically How to hide navigation bar permanently in android activity? Video 100% width and height How to open a web page automatically in full screen mode Full-screen responsive background image JFrame in full screen Java How to set maximum fullscreen in vmware? Chrome Fullscreen API