Solved

H1 Vertical align middle

Posted on 2004-08-12
3
1,452 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
  • 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Wrapper for APPs 9 86
push logos in footer up higher 5 25
Flex container exceeding stated width in IE11 4 15
Bootstrap list items overlap 3 12
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

807 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