Results 1 to 4 of 4

Thread: vertical-align: middle not working

  1. #1
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default vertical-align: middle not working

    Hello,

    I'm trying to vertically align my text inside a div. The div itself is inside a table cell. But the text is not vertically aligned.

    Here's a screen shot of the HTML after hitting F12 in IE:

    Click image for larger version. 

Name:	html.jpg 
Views:	403 
Size:	44.9 KB 
ID:	5581

    The div I'm interested in is the one with id="moduleTemplate0".

    Here is the CSS:

    Code:
    table.gridTable {
        animation-duration: 1s;
        animation-name: activateObjective;
        animation-timing-function: ease-in;
        animation-iteration-count: 1;
    }
    
    .gridModuleNameColumn 
    {
        background-color: #0072C5;
        padding-left: 0px; /*10px;*/
        padding-right: 0px; /*10px;*/
        padding-top: 0;
        padding-bottom: 0;
        margin: 0;
        position: relative;
        width: 240px;
        /*border-top: 1px solid black;
        border-left: 1px solid black;*/
    }
    
    .gridModuleNameColumn > div.textStyle {
        font-size: 1.3em;
        color: #FFFFFF;
    }
    
    .moduleBorder
    {
        height: 43px;
        border-top: 1px solid black;
        border-left: 1px solid black;
        padding-left: 10px;
        vertical-align: middle;
    }
    Can anyone tell me why vertical-align: middle isn't working in .moduleBorder?

  2. #2
    Join Date
    Aug 2009
    Location
    utf-8
    Posts
    205
    Thanks
    4
    Thanked 7 Times in 7 Posts

    Default

    What version of IE are you using? Also is there any link to a site to see the full code?
    An inline div is a freak of the web and should be beaten until it becomes a span

  3. #3
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Apply it to the td rather than contents. http://www.w3schools.com/css/css_table.asp

    If you need more help, please provide a link to your page.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  4. #4
    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

    Also, bear in mind that vertical-align is one of those dual purpose properties. As Beverley points out - it's a bit more consistent as a property of a table cell (td or th) - but only as regards inline elements that are the cell's immediate children (assuming there's adequate space, etc.), without block level elements being in the cell (that can often throw it off). In my experience it has more use (since tables are generally discouraged in layout except for tabular data) in it's other role, which is as a sort of relative property among two or (usually more effective, even) more inline elements. Say you have three spans in a row, or a span followed by an a then another span. Making the element in the middle vertical-align: middle should center it vertically relative to the two surrounding inline elements. If these (the surrounding inline elements) have a common apparent height, the effect can be good.

    Bottom line - in my opinion, you're right. It doesn't work. You can work it to good effect in certain limited situations.

    Using margin and/or padding of both the element(s) you're concerned with and its/their parent are often more effective, especially if they're block level or can be made display: block.

    One final thing on this for now - even given all I've put forth, different browsers can sometimes render vertical-align differently. It's not something to be relied upon for anything requiring precise layout. Luckily - very few things do, or at least very few things should require precise layout.
    - John
    ________________________

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

Similar Threads

  1. Valign to middle not working
    By n3wb1e in forum CSS
    Replies: 2
    Last Post: 05-22-2011, 03:23 PM
  2. flexislide and vertical alignment (middle)?
    By thorirv in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 02-01-2010, 09:21 PM
  3. Resolved Vertical Middle align with search box
    By Ryan Fitton in forum CSS
    Replies: 0
    Last Post: 03-10-2009, 09:45 PM
  4. align text in middle of menu
    By geoffb in forum CSS
    Replies: 1
    Last Post: 10-01-2006, 09:22 AM
  5. Using Vertical Align
    By dog in forum CSS
    Replies: 4
    Last Post: 06-21-2006, 11:15 PM

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
  •