473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to center a table vertically

Hello,

I am not 100 percent good w/ php or css... but I use the web well and I am able to find what I need, but this one little thing.


I have a website, and its only a box that I want in the middle of the screen, everything in this box is in a table.

But what I need to be able to do is, to put in the the middle of the screen, no matter if you are running 800x600 or 1920x1200 res. I want it always in the middle of the screen, I can get it for one, but any time I change, its either higher or lower...

any help would be greatful :)

thanks
Aug 31 '07 #1
4 1947
ak1dnar
1,584 Expert 1GB
Welcome to the TheScripts.com, sationus !

I think you can get answers from HTML/CSS forum rather than Php forum. So I'll move this from Php Forum. Thanks!
Aug 31 '07 #2
Atli
5,058 Expert 4TB
Hi sationus. Welcome to TSDN!

I have edited the title of the thread. Please try using descriptive thread titles and avoid using phrases like 'please help'. Threads with poor titles actually receive FEWER responses!

Check out our Posting Guidelines for more information on TSDN posting policies.
Aug 31 '07 #3
Hi sationus. Welcome to TSDN!

I have edited the title of the thread. Please try using descriptive thread titles and avoid using phrases like 'please help'. Threads with poor titles actually receive FEWER responses!

Check out our Posting Guidelines for more information on TSDN posting policies.
ok sounds good, sorry bout that
Aug 31 '07 #4
markrawlingson
346 Expert 100+
Probably the best way to do this is to use javascript because you can access the screen height/width since it is a client side language. From there, it's a simpe mathematics issue.

Once you know the screen dimensions (ie: 800/600, 1025/768, etc) - the middle of the screen is width/2 or height/2 right? That's half the equation. The other half is finding the height and width of your box object, if you want the box to be in the middle then the equation you want to find both the middle of the screen, and the middle of the object, subtract - and VOILA!

Try the following:

Expand|Select|Wrap|Line Numbers
  1. function doCenter() {
  2.      var obj = document.getElementById('yourelementsid');
  3.      obj.style.top = (screen.height/2) - (obj.style.height/2);
  4.      obj.style.left = (screen.width/2) - (obj.style.width/2);
  5. }
  6. document.onload = doCenter;
  7.  
I employ this method whenever i open a popup window so that the popup centers right smack dab in the middle of the screen, no matter what screen resolution the user has.

Hope that helps!
Sincerely,
Mark
Aug 31 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tony Vasquez | last post by:
Can somoene give me an example of how to center a div, according to it's image size... I am using different images, and so I have to resize it in a functino according to the image's size. So I use...
27
by: FL | last post by:
Hi Everyone, I know howto center a block using margin-left: auto ; margin-right: auto ; but I'm trying to center vertically a box, any idea to solve this?
10
by: john T | last post by:
Is there anyway to vertically center a html table using css in such a way it does not alter the html table. When I tryied it just screws up.
10
by: Unknown User | last post by:
Yet another question about vertical centering: How can I center a page vertically? I have searched on Google and didn't find anything that works at least on IE, Opera and Mozilla:...
11
by: Serg | last post by:
I had some CSS problems, and they were solved by someone who pointed out to me that I should have <!DOCTYPE ..... at the top of my code, which I now do. And it fixed all the inheritance...
1
by: Rabbit | last post by:
Dear All I'm new to use ASP.Net for developement, can someone tell me how can I create a web form with size say 300px x 300px, align vertically center on the page Because so far I can use Div...
4
by: John | last post by:
Is it possible to center a memo field value vertically? I use a memo field for printing address labels and I would like the addresses to show up centered vertically. Thanks, john
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.