Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a full screen div, and prevent size to be changed by content?

Tags:

css

fullscreen

for my web application, i would like the main div to be full screen (both width and height = 100%), and regardless of content, i want it to stay at that size. that means, if there are not much content, it shouldn't shrink, and if there are too much content, it shouldn't push this main div.

how can i do this?

(i'm ok with hacks applied to this div, as long as it will keep contents hack-free)

like image 983
throwaway007 Avatar asked Jul 18 '10 16:07

throwaway007


People also ask

How do I make a div stay the same size?

if you set width:500px; and height:300px; (or whatever size you want) the div should stay the same size. Also, you can set overflow:hidden; so that if whatever is in the div goes beyond those bounds, it is not shown, and does not resize the div. Show activity on this post. Try this one.

How do you make a div fit the whole screen?

position:absolute You can also use position absolute as well as set all the viewport sides (top, right, bottom, left) to 0px will make the div take the full screen.

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 you auto adjust the div width according to content in it?

One way you can achieve this is setting display: inline-block; on the div . It is by default a block element, which will always fill the width it can fill (unless specifying width of course).


1 Answers

Or even just:

<div id="full-size">   Your contents go here </div> 
html,body{ margin:0; padding:0; height:100%; width:100%; } #full-size{   height:100%;   width:100%;   overflow:hidden; /* or overflow:auto; if you want scrollbars */ } 

(html, body can be set to like.. 95%-99% or some such to account for slight inconsistencies in margins, etc.)

like image 59
lucideer Avatar answered Sep 19 '22 02:09

lucideer