Link to home
Start Free TrialLog in
Avatar of BeginningWebDesign
BeginningWebDesign

asked on

H1 Vertical align middle

Hello

can anyone help solve this problem, i'm trying to align the h1 element so that it appears in the center of the th cell, but i cannot seem to get it to work. I have supplied the code below.
// header cell
#CouCssHPT TH {
      background-color: #A9B9D1;
      color: #191970;
      border: 1px solid #A9B9D1;
      padding: 5px;
}

Div#HeaderBorder {
      background-color: transparent;
      color: #191970;
      padding: 3px;
      border: 1px solid White;
      width: 95%;
}

Div#HeaderBorder h1 {
      background-color: transparent;
      color: #191970;
      font-family: Arial, Helvetica, sans-serif;
                font-size: 100%;
      font-weight: bold;
      vertical-align: middle;
      text-align: center;
}

<th colspan="3"><div id="HeaderBorder"><h1>Book review</h1></div></th>

Thank You
Caz
ASKER CERTIFIED SOLUTION
Avatar of mreuring
mreuring
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BeginningWebDesign
BeginningWebDesign

ASKER

Hi Martin

Thanks what does the: display: inline do?

Caz
Based on minimal support (being IE) display can set a few modes block, inline, list-item and none. There's a fair few others but those are mostly irrelevant or not supported in IE and hence mostly useless in a commercial site.
- none: Don't display this element or anything it contains
- inline: This element and it's containers are text. This means not principal block is generated the content is really just text.
- block: Generate a principal block. A box is generated, just picture the contents as having a square fence. Block elements are not considdered text and are not affected by alignments of text.
- list-item: Generates a box with a preceding box containing a marker.

Like I mentioned a block element does not listen to text-align (or vertical-align for that matter) of it's parent. Also it generates , by default, a box which is just large enough to contain it's contents. In your situation you needed the text of the h1 to be centered vertically according to the size of your th. The easiest way to go about doing this was to stop the h1 from generating it's own block, in order to do this you set it to inline and it becomes just another line of text, which does listen to the vertical-align of the th.

It's a concept I find hard to explain, so I hope this was clear enough :)

 Martin

btw, for the specs: http://www.w3.org/TR/CSS2/visuren.html#propdef-display