Hello everybody!
So I have this problem with centering vertically. I found this page about vertical-centering-with-css but none of these 5 posibilities solves my problem.
I have a div#mapAndQuestions in which I have a
- on the left side and a image on the right side.
div#mapAndQuestions
{
height:60%;
min-height:200px;
}
so this div#mapAndQuestions resizes whenever the browser windows is being resized but it stops ar 200px;
and
ul#questions
{
height: 300px;
display:table-cell;
vertical-align:middle;
}
in this solution when display:table-cell; vertical-align:middle;I have to define the height of
- in px because it will not work in % but I would like to define the height 100% so it fits the parent DIV but as I said % does not work with display: table-cell. so 300px is only approximately 60%.
and one more thing that I can not position nor relatively or absolutely this
- in this case
this solution is only nearly good but may be there is a perfect solution?
maybe JavaScript would help?
Does the following do what
Does the following do what you want? It's adapted from my demos, vertical centering using css.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta name="generator" content= "HTML Tidy for Linux (vers 7 December 2008), see <a href="http://www.w3.org" rel="nofollow">www.w3.org</a>" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Nested Centering Test</title> <style type="text/css"> /*<![CDATA[*/ html { display: table; height: 100%; } body { display: table-cell; vertical-align: middle; } p, h1 { margin-bottom: 0; } ul { background-color: blue; border: 2px solid red; list-style: none; margin: 1em auto 0; padding: 20px; text-align: center; word-spacing: -.3em; } li { border: 1px solid black; display: -moz-inline-box; display: inline-block; margin-left: -1px; vertical-align: middle; word-spacing: 0; } * html li { display: inline; } *+html li { display: inline; } a { display: block; padding: .6em; background-color: blue; color: #fff; text-decoration: none; } a:hover { background: #fff; color: #009; } /*]]>*/ </style><!--[if lt IE 8]> <style type="text/css"> body { top: 50%; left: 0; position: relative; zoom: 1; } h1, p, ul { position: relative; top: -50%; } </style> <![endif]--> </head> <body> <h1>Centering a Floated Widthless Navbar.</h1> <p>Tested in IE 6-8, FF 2&3.5, Opera 10, and Safari/Win 4.</p> <ul id="navbar"> <li><a href="#">Link One</a></li> <li><a href="#">Link Two <br /> on two lines</a></li> <li><a href="#">Link Three running on a bit</a></li> <li><a href="#">Link Four</a></li> <li><a href="#">Link Five</a></li> </ul> <p>The menu above is be both vertically and horizontally centered in the red bordered blue container.</p> </body> </html>
cheers,
gary
thx for your advice. I see
thx for your advice.
I see what you were trying to achieve with
html {display: table
}
and
body {display: table-cell;
vertical-align: middle;
}
but I do not see how your list is centered because if I set the height of [ul] ie 400px then it is not centered vertically.
if I put [ul] in a [div style="height:400px"] then this is not centered vertically
I'm not sure what end result
I'm not sure what end result you want. See centering inline elements. If that's (the last example) not helpful, show us an image of what you want.
cheers,
gary
