![]() |
![]() |
#1 (permalink) |
paranoid
Location: The Netherlands
|
[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!
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. " - Murphy MacManus (Boondock Saints) |
![]() |
![]() |
#2 (permalink) |
Junkie
|
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] |
![]() |
![]() |
#4 (permalink) |
paranoid
Location: The Netherlands
|
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...
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. " - Murphy MacManus (Boondock Saints) |
![]() |
![]() |
#6 (permalink) | |
paranoid
Location: The Netherlands
|
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.
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. " - Murphy MacManus (Boondock Saints) |
|
![]() |
![]() |
#7 (permalink) |
Psycho
Location: sc
|
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:
|
![]() |
![]() |
#8 (permalink) |
Psycho
Location: ask your mom
|
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
__________________
aaarrrrrgggghhhh!!!! |
![]() |
![]() |
#10 (permalink) | |
paranoid
Location: The Netherlands
|
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".
__________________
"Do not kill. Do not rape. Do not steal. These are principles which every man of every faith can embrace. " - Murphy MacManus (Boondock Saints) |
|
![]() |
![]() |
#12 (permalink) |
beauty in the breakdown
Location: Chapel Hill, NC
|
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
![]()
__________________
"Good people do not need laws to tell them to act responsibly, while bad people will find a way around the laws." --Plato |
![]() |
![]() |
#13 (permalink) |
Tilted
Location: south east
|
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
__________________
Zero Cool stay sexy |
![]() |
![]() |
#14 (permalink) | |
PIKE!
|
Quote:
From what I know, there's currently no way to do this except with javascript. |
|
![]() |
![]() |
#16 (permalink) |
Psycho
Location: sc
|
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:
__________________
This is what is hardest: to close the open hand because one loves.
Nietzsche |
![]() |
Tags |
centering, html or css, vertical |
|
|