Results 1 to 4 of 4

Thread: divs tops not aligning

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

    Default divs tops not aligning

    Please have a look at the following HTML:

    Code:
    <html>
    <head></head>
    <body>
    <div style="background-color: red; display: inline-block;">
    line 1<br>
    line 2
    </div>
    <div style="background-color: blue; display: inline-block; padding-top: 20px;">
    line 1<br>
    line 2
    </div>
    </body>
    </html>
    I have two divs both inline-block. The first one is red and the second one blue. The blue one has padding-top: 20px. This seems to be forcing the red one to have a top margin. I'm not sure how to set the divs to have their tops aligned. Can anyone tell me how this is done?

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

    Default

    I think I've mentioned the box-model to you before - it is affected by padding and borders. You should look in to that and also the vertical-align property for inline-elements.
    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

  3. #3
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Vertical alignment:
    Code:
    <div style="background-color: red; display: inline-block; vertical-align: top">
    line 1<br>
    line 2
    </div>
    <div style="background-color: blue; display: inline-block; padding-top: 20px;">
    line 1<br>
    line 2
    </div>

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

    Default

    Thanks both,

    This works.

Similar Threads

  1. Resolved Aligning divs
    By Mirawr in forum HTML
    Replies: 6
    Last Post: 07-03-2011, 07:46 PM
  2. Replies: 5
    Last Post: 05-27-2009, 11:14 PM
  3. Aligning 3 small divs within a div
    By lulurock in forum CSS
    Replies: 0
    Last Post: 07-22-2008, 11:35 PM
  4. aligning divs
    By chechu in forum Looking for such a script or service
    Replies: 8
    Last Post: 09-24-2007, 11:43 PM
  5. aligning divs on same row help!!!
    By moisea in forum CSS
    Replies: 5
    Last Post: 03-07-2007, 09:11 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
  •