Solved

H1 Vertical align middle

Posted on 2004-08-12
3
1,453 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:BeginningWebDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
mreuring earned 500 total points
ID: 11790889
This should work:
#CouCssHPT TH {
     background-color: #A9B9D1;
     color: #191970;
     border: 1px solid #A9B9D1;
     padding: 5px;
     vertical-align: middle;
}

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;
     text-align: center;
       display:inline;
}

I placed the vertical-align on the th instead of the h1 and added the display: inline to the h1 to make it normal text, which is then governed by it's parent.

Hope this helps,

  Martin
0
 

Author Comment

by:BeginningWebDesign
ID: 11790927
Hi Martin

Thanks what does the: display: inline do?

Caz
0
 
LVL 17

Expert Comment

by:mreuring
ID: 11790976
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question