Results 1 to 3 of 3

Thread: Valign to middle not working

  1. #1
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Valign to middle not working

    I have a cell containing a div tag which itself contains an image. When the page loads, the image loads at the top of the cell and not the middle. Ive specified middle alignment in the cell and also the CSS but it still stubbornly stays at the top.

    --------------HTML----------------
    <td colspan="2" height="220" valign="middle">
    <div class="headerLogoMainPage"><img src="images/HCLogo.gif" width="210" height="116" /></div></td>


    -------------CSS---------------------
    .headerLogoMainPage{
    height: 220px;
    float:left;
    width: 210px;
    background-image:url(../images/GradientBackground.gif);
    vertical-align:middle;}

    Thanks for any help.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    vAlign and vertical-align don't apply to divisions.

    Code:
    .headerLogoMainPage img {
    	display: block;
    	margin-top: 52px;
    }
    should do the trick. 52 is the height of the div (also happens to be the height of the td, which helps make this work) minus the height of the image divided by 2.

    Alternatively, if you skipped the division and put the background image as style to the td and plopped the image directly in the td, the td's vAlign would work. It's deprecated though, so instead, set it as vertical-align for the td in the stylesheet:

    HTML Code:
    <td class="headerLogoMainPage" colspan="2">
     <img src="images/HCLogo.gif" alt="" /></td>
    Code:
    .headerLogoMainPage { 
    	height: 220px;
    	text-align: left;
    	vertical-align: middle;
    	background-image: url(../images/GradientBackground.gif);
    }
    
    .headerLogoMainPage img {
    	width: 210px;
    	height: 116px;
    }
    Last edited by jscheuer1; 05-20-2011 at 06:23 PM. Reason: add detail
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much John, that worked nicely.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •