Hope someone can help with this - I’m just trying to vertical-align some text in a <div> - its the top row in an inset box, where the text will either take up one line or two.
That won’t work I’m afraid as vertical-align (outside of table-cells) only applies to inline elements on the same line. It will not align two or more lines.
For IE8+ you could add an inner span element and turn it into a table-cell element as follows.
If you had just one line of text and the text did not wrap then you could set the line-height to the same height as the div (27px in the example above) and that one line of text would automatically be centred. However it won’t work for 2 lines of text because when the text wraps each line will be 27px apart.
Vertical align only applies to inline elements on the same single line (unless they are table-cells or display:table-cell). It does not apply to two or more lines unless the lines are wrapped in an inline block and there is an other inline-block element on the same line that they can line up against (as shown clearly in Gary’s article I linked to above).
@Paul Where can i find a good reference that explains in detail how display property works ( in combination to other properties as well) ?
The sitepoint reference (written by Tommy and me) gives you the solid details but is not a tutorial as such.
The w3c visual formatting model is the ultimate resource but is hard to digest unless you are familiar with the terminology.