I want to make a div fit the initial height and width of a users screen.
I think the following crudely drawn diagram explain this better:
#div { width: 100%; height: 100%; }
does not seem to work
You can simply use the CSS display property with the value inline-block to make a <div> not larger than its contents (i.e. only expand to as wide as its contents).
Easiest way to center something regardless of page width is margin: auto; in your CSS, with height and width defined. Show activity on this post. This will center your DIV with class center-div horizontally AND vertically. The margin-left must be negative half of what your width is.
The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.
If I understand correctly (there's some room for confusion here):
http://jsfiddle.net/zRpNp/
#screenFiller { position: absolute; top: 0; right: 0; bottom: 0; left: 0; border: 15px solid orange }
You might be after the position: fixed
version: http://jsfiddle.net/zRpNp/1/
Personally I like the pure CSS solution. Just use the vh
unit.
#filldiv { height: 100vh; }
That will make the div fill the height of the browser window.
In addition, you can also make it fill the width of the browser window, this only uses the vw
unit.
#filldiv { width: 100vw; }
Both are shown in this fiddle
I personally really like both of these units because they can be used for dynamic resizing of things such as font sizes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With