setting this property to “middle” should do just that: vertical-align an element to middle (i.e., equal amount of white space above and below element… for example a div with text inside another div… in my case content will be inserted dynamically and I don’t know how many lines of text it will be; it has to be middle-aligned vertically in all cases…)
display:table-cell does not work in all browsers, so that’s a non-starter…
I get so sick of this problem… why can’t vertical-align:middle ever work as it should? (like text-align:center; this always works… why doesn’t vertical-align:middle ever work???)
What the page you linked to fails to mention is that the vertical-align property only works with inline elements and not block-level elements. A <div> is a block-level element, so vertical-align can’t ever work unless you modify its state, e.g. set its display to a non-block value.
@Paul_O_B; has some examples on how you can accomplish vertical centering/aligning. See here: http://pmob.co.uk/
As Maleika said above vertical-align only applies to inline elements (and table-cells). It was never meant to vertically align block elements.
display:table-cell is the easiest solution and works in IE8+ and all other browsers that are in use. If you want IE7 support then you need to add a hack like this:
If it is anything like what you want, I’ll be more than happy to provide you the HTML and CSS. It’s the least I can do after what they have done for me
You’ll need to show us some code if you want more specific help.
You shouldn’t need to float the element if using display:table-cell properties because the cells will naturally be adjacent to each other. If using display:table structures you can use display:inline-table for tables aligned next to each other.
It all does depend on what you are doing though so we would need to see the code.
hmmm… ok, I see, Paul… I would have to change the layout of the entire thing (just two divs side-by-side, actually… from floated divs to display:table-cell… hmmm… we don’t officially support IE7 anymore, but ideally I’d still rather go with a solution that will work in IE7 also…
interesting about display:table-cell: it doesn’t respect margins!! (of course, td’s don’t have margins…)
here are two examples: one with display:table-cell and one with floats…
table-cell you can do vertical-align:middle, but you can’t have a margin… (I suppose a solution can be found to fix the margin issue…
well, other possibility is to use JS to vertical-align the elements (again, I won’t know height of container of dynamic content…), which I actually did already, it works quite well (and the entire thing (my thingie with two divs) depends on JS to show up on the page anyway), but well, still trying to decide (advantage of JS option is it would work in IE7 too…)
You can control the spacing between cells with border-spacing.
#outer{border-spacing:10px}
It’s not the same as margins but you can get pretty close to what you want. Sometimes it means making the outer stretch wider than you want so that the cells remain the size you wanted.
If you want older browser support then here a few old examples: