Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Nested DIV tag alignment: ISSUE

    I have two div tags, nested within another container div tag.

    I know that this may be a simple problem, however i am unable to align the two side by side.

    the code is as follows:

    Code:
    <div id="Container">
    
    <div id="Ingredients">
    <!-- List of ingredients is contained here -->
    </div>
    
    <div id="Instructions">
    <!-- Instructions for recipe goes here -->
    </div>
    
    </div>
    I've tried using float:left/float:right for each, and neither seems to work.

    All help would be appreciated.

  • #2
    New to the CF scene
    Join Date
    Jun 2009
    Location
    Romania
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Im not an expert but try this.

    Code:
    <style>
    
    #Ingredients,#Instructions {
    float: left;
    padding: 2 2 0 0
    }
    
    </style>
    do you have any style rules for the #container?
    Last edited by lordmeka; 06-21-2009 at 11:57 AM.

  • #3
    New Coder
    Join Date
    Jun 2009
    Location
    Bangalore, India
    Posts
    42
    Thanks
    3
    Thanked 4 Times in 4 Posts
    <div> is a block element, which means that it takes up all the horizontal space available and does not let anything else next to it.

    So, you'll have to use tables instead:

    Code:
    <div id="Container">
    <table border="0">
    <tr>
    <td>
    <div id="Ingredients">
    <!-- List of ingredients is contained here -->
    </div>
    </td>
    <td>
    <div id="Instructions">
    <!-- Instructions for recipe goes here -->
    </div>
    </td>
    </tr>
    </div>

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    I've tried using float:left/float:right for each, and neither seems to work.
    float:left; should work if used properly. Could you post your complete code including DOCTYPE?
    So, you'll have to use tables instead:
    Never! Never use tables for making your layout.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    The PHP Guy (06-21-2009)

  • #5
    New Coder
    Join Date
    Jun 2009
    Location
    Bangalore, India
    Posts
    42
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by abduraooft View Post
    Never use tables for making your layout
    Thanks for the link. I found it interesting (and funny )

    BUT, how does CSS solve the problem in this case? OP's only option, I recon is to use inline elements like <span>

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Have a look at some common layouts without any tables at http://bonrouge.com/3c-hf-fluid.php ( you might get interested in the beauty of CSS designs at csszengarden )
    Last edited by abduraooft; 06-21-2009 at 03:35 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    The PHP Guy (06-21-2009)

  • #7
    New Coder
    Join Date
    Jun 2009
    Location
    Bangalore, India
    Posts
    42
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Lightbulb

    You were right..

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>No Tables</title>
    <style>
    div
    {
        border: 2px solid black;
    }
    #Container
    {
        border-style: none;
    }
    #Ingredients
    {
        float: left;
    }
    #Instructions
    {
        float: right;
    }
    </style>
    </head>
    <body>
    <div id="Container">
    
    <div id="Ingredients">
    <!-- List of ingredients is contained here -->
    Ingredients
    </div>
    
    <div id="Instructions">
    <!-- Instructions for recipe goes here -->
    Instructions
    </div>
    
    </div>
    </body>
    </html>
    Works!!

    I really need to sharpen my CSS skills

    Thank you, you really inspired me!

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    You are welcome, but your current DOCTYPE is incomplete, which may turn IE into quirks mode. See http://www.alistapart.com/articles/doctype/
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    New Coder
    Join Date
    Jun 2009
    Location
    Bangalore, India
    Posts
    42
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by abduraooft View Post
    You are welcome, but your current DOCTYPE is incomplete
    I knew that...

    I didn't care about that as I just wanted to see if you were right..

    btw, float:left and float:right work well even if I don't specify a DOCTYPE


  •  

    Posting Permissions

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