473,372 Members | 1,076 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,372 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 1946
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
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.