whats the best way to make a div 100% of screen in order to center it?
Main Topics
Browse All TopicsI want to simulate "dimming" the page and placing a div centered on the screen as a dialog box.
I thought of streching a div to 100% x 100% of screen size and then just using bg color black with alpha and then putting another div inside it as the dialong.
is this the best way to go?
can i just alpha the <body>?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You may find it better to change the text color (and if necessary the background color) to a darker color and not use the div and alpha. Many browsers don't support alpha and IE and the others that do, do it differently. This will achieve your affect and avoid the centering question (maybe, see next).
Without a specified width, a block element, like a div, takes the full (100%) width available and minimum height. You would have only to specify height 100%; although, that is not always consistent across browsers in getting it to the bottom of the window.
To center a box with a specified width and height in a space, position it absolutely and then use negative margins of half the boxes dimension like this:
#centered-box {
width: 200px;
height: 200px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
}
I've used the technique neester propses before too. The advantage of this is that the mask DIV covers the whole page, and so stops the user clicking other links/controls on the page (more like a true dialog). If you use a checkboard gif (4x4 pixels, with alternating grey/transparent colours) you don't need to worry about how browsers handle transparency.
If you're just worried about the visual 'dimming', another method would be to define a separate set of styles based on a body selector for the dimmed colour scheme. Then to dim everything on the page, just swap the class on the body element with Javascript.
body.dimmed {
color:#DDDDDD;
background-color:#DDDDDD;
}
You'll need to make sure your dialog styling uses a specific selector so it overrides the .dimmed on the body. Using an ID (and optionally !important) should work:
#dialog {
color:#000000;
background-color:#FFFFFF;
}
Business Accounts
Answer for Membership
by: RoonaanPosted on 2006-01-06 at 16:13:30ID: 15634816
If you alpha the body you would be alphaing your dialog also.
You could try though to have a wrapper setup like this, where you do the alpha trick on the content div:
<body>
<div id="dialog" style="display:none">..we use this to display a dialog later one..</div>
<div id="wrapper">
.... all the sites other contents
</div>
</body>
-r-