Solved

H1 Vertical align middle

Posted on 2004-08-12
3
1,448 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
Comment Utility
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
Comment Utility
Hi Martin

Thanks what does the: display: inline do?

Caz
0
 
LVL 17

Expert Comment

by:mreuring
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now