![]() |
[html/css] vertical centering...
Hi,
I'd like to have a single block of text on a page, centered vertically and horizontally. (using css) The last part is easy: text-align: center; but the vertical centering is eluding me. Can anyone help? So far I haven't been able to vertically center anything... current code (index.html) : PHP Code:
PHP Code:
Any tips (on this and CSS general) greatly appreciated! |
What browser are you using? The vertical-align property generally works in Internet Explorer but not in Mozilla, as near as I can tell.
If all else fails, you could use a JavaScript to move the DIV to the center of the page: PHP Code:
[Chandler]Could the posting textarea be any smaller on this site?[/Chandler] |
|
I've tried my code with IE6 and Opera 7.5
I'll try to use both your info and see what I can come up with... |
I always put it in a table, and have the top row have a height of 40%.
Works good, mostly, even on old browsers. |
Quote:
With pictures I can use vertical-align and no matter what size the picture is (useful when displaying a random image each time) it will always be centered. No such luck with other objects, I can't get them centered. I've not looked at it for two days, perhaps tomorrow I'll try again. |
well,
i came up with a quick solution that works in ie but not in opera, didn't try mozilla. don't have the time right now to play around with it, have to go do somefin. might play with it later. PHP Code:
|
try removing your doctype.
the easiest way i've found to do a fully centered block or image is to use the table within a table trick. set the outer table's width AND height to 100%. setup one table row and one table cell. set the valign for that cell to middle and align to center. inside that table cell, setup the inner table for your content. keep in mind, this is a hackjob way of doing it so if you are concerned about validating your html, it won't fully validate. (height definition for table is not CSS compliant.... or something like that). you also need to remove your doctype or set it to loose or transitional. here's an example: http://www.disivion.com/songs/listing.html |
|
Quote:
I could use one of the tricks, also mentioned in an earlier post to put the element at 50%, and then set the margin negative to half the size of the content (i.e. -200px for an element that is 400px high), but that would require fore-knowledge of the content size, something that is not necessary for say: "text-align: center". |
I just thought of something else. The vertical-align property aligns the content of an element, not the element itself. To center a DIV on a page, try applying text-align and vertical-align to the BODY, not the DIV.
|
There isnt any good way of doing it. It annoys me, too. The only one I know of is, like others said, the table hack :(
|
try this, its always worked for me.
try placing your content in a table and in the <td> tags add a valign varible and then set the class as centered text or what ever you had it on your style sheet as. so it looks like this <td valign="middle" class="centeredtext"> that should do it.. thats just my 2 cents |
Quote:
From what I know, there's currently no way to do this except with javascript. |
I just did a new site and found that vertical-align simply doesn't work in Mozilla period. That's a curious oversight in a browser that prides itself on having a complete CSS implementation.
|
well... no thats not true...
(i'm back and now i have an answer) here try this, which works perfectly for me in both ie and mozilla: PHP Code:
|
All times are GMT -8. The time now is 01:14 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project