Select Categories Below
Advertisement
Start Your Own Q&A Site
Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.
Status: Open Points: 75 Time: 07:17 - Aug 04, 2008
david
I need to center a div on the screen (through javascript), but I'm having trouble doing so. This is my code: var objLeft = (document.body.clientWidth - pleaseWaitBox.offsetWidth) / 2; var objTop = (document.body.clientHeight - pleaseWaitBox.offsetHeight) / 2; objLeft = objLeft + document.body.scrollLeft; objTop = objTop + document.body.scrollTop; // Position object pleaseWaitBox.style.position = "absolute"; pleaseWaitBox.style.top = objTop + "px"; pleaseWaitBox.style.left = objLeft + "px"; Do you know what I'm doing wrong or if there is another better way of doing it? Thanks, David
Categories:
Add Categories
When adding more than one category, separate them with commas.
vivekwin09
Date:: Aug 05, 2008
Time:: 09:03
this very easy to center the div . <div algin="center"><div></div></div>
Date:: Aug 06, 2008
Time:: 11:28
Sorry, but I think you misunderstood my question. It needs to be horizontically and vertically centered and working also if the user has scrolled down on the page.
Muhammad Amman
Date:: Sep 08, 2009
Time:: 05:31
Mr.David it is better that u first define main div then apply ur code with in that div ok...
admin
Date:: Nov 27, 2009
Time:: 09:15
The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points. The Quomon Team
roooberto
Date:: Mar 16, 2010
Time:: 19:04
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Example Vertical alignment of content with JavaScript & Horizontal with CSS</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <style type="text/css"> <!-- body { margin: 0; padding: 0; font: 12px/1.5 verdana, arial, helvetica, sans-serif; text-align: center; /* Takes care of horizontal alignment in Internet Explorer */ } #content { position: relative; /* Needed for Safari */ margin: auto; /* Takes care of horizontal alignment in standards compliant browsers */ text-align: left; width: 600px; height: 200px; background-color: #fc0; } h1, p { margin: 0; padding: 1em; } h1 { font-size: 12px; line-height: 1.5em; } --> </style> <script type="text/javascript"> <!-- function getWindowHeight() { var windowHeight = 0; if (typeof(window.innerHeight) == 'number') { windowHeight = window.innerHeight; } else { if (document.documentElement && document.documentElement.clientHeight) { windowHeight = document.documentElement.clientHeight; } else { if (document.body && document.body.clientHeight) { windowHeight = document.body.clientHeight; } } } return windowHeight; } function setContent() { if (document.getElementById) { var windowHeight = getWindowHeight(); if (windowHeight > 0) { var contentElement = document.getElementById('content'); var contentHeight = contentElement.offsetHeight; if (windowHeight - contentHeight > 0) { contentElement.style.position = 'relative'; contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px'; } else { contentElement.style.position = 'static'; } } } } window.onload = function() { setContent(); } window.onresize = function() { setContent(); } //--> </script> </head> <body> <div id="content"> <h1>Content</h1> <p>This content should be centered in your browser window. CSS is used for horizontal alignment, while scripting is used for vertical alignment.</p> </div> </body> </html>
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Questions
whats the best food to eat during midnight?
How to identify the tiffany jewelry? www.tffanycheapmall.com.
Send an email alert to each user of the php application based on criteria
How I Increased My AdSense Earnings?
how to choose the lady dress ?
How can I fulfill the minimum requirement to make your computer support 3D?
You have 100 characters to use
Rank
Expert
Points
1.
10354
2.
6493
3.
5596
4.
4848
5.
3487
6.
2840
7.
2770
8.
2303
9.
1820
10.
917
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software