Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a div fit the initial screen

Tags:

html

css

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:

enter image description here

#div {  width: 100%;  height: 100%; } 

does not seem to work

like image 497
jonnnnnnnnnie Avatar asked Jun 08 '11 22:06

jonnnnnnnnnie


People also ask

How do you make a div fit its content?

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).

How do I center a div according to my screen size?

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.

How do you make a div occupy full width?

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.


2 Answers

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/

like image 158
thirtydot Avatar answered Sep 18 '22 03:09

thirtydot


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.

like image 40
tinfoilboy Avatar answered Sep 20 '22 03:09

tinfoilboy