CSS positioning?

Discussion in 'CSS' started by goldensea80, May 14, 2006.

  1. #1
    I am quite new at CSS positioning. I am still confusing at how to place a div blog from left to right like and top to bottom like this. Forgive me if this is too simple to implement with you.
    
    +-------++-------++-------+
    | div1  || div2  || div3  | 
    +-------++-------++-------+
    +-------------------------+
    |          div4           | 
    +-------------------------+
    
    Code (markup):

     
    goldensea80, May 14, 2006 IP
  2. johneva

    johneva Well-Known Member

    Messages:
    1,480
    Likes Received:
    46
    Best Answers:
    1
    Trophy Points:
    170
    #2
    Basicly the best way is to set the widths for the left and right div then, float the left div left, float the right div right and then use margins for the center div to position it in the middle of the two other divs. Then to get the next div to go on the next level like div 4 in your diagram you have to clear both floats. ;)

    Here is an exellent tutorial on the Holy Grail layout.
     
    johneva, May 14, 2006 IP
  3. AdamSee

    AdamSee Well-Known Member

    Messages:
    422
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    135
    #3
    I prefer floating all the elements so that they are all effected by the presence of the other.

    Div 1 - float left, Div 2 - float left, Div - 3 float right
    clear both
    Div 4 - float left,
    clear left
     
    AdamSee, May 14, 2006 IP
  4. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #4
    What I want is to do what tables can do, for example I have a fix width=780px at the center of the page nomatter what size the browser is. (like my website, check my sig, currently use tables 'cause I was stucked with css)
    I've check the Holy Grail example, but when I resize the browse, the middle column is resized and that's not the case.
    It seems that the most important properties in CSS positioning is float and clear? Can some body give a simple and easy to understand of them? I've read the official site but it's still confusing.
     
    goldensea80, May 15, 2006 IP
  5. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #5
    You've pretty well described not only what you want but also how to get it. Begin with an over-all container; call it #wrapper
    
    #wrapper {
        width: 780px;
        margin: 0 auto;
        }
    Code (markup):
    Now let's style the three across columns. We'll use an IE safe method that avoids some of the bugginess that PoS brings to the table.
    
    #colA {
        width: 254px;  /*somewhat less than â…“ of the page width*/
        float: left;
        }
    
    #colC {
        width: 254px;
        float: right;
        }
    
    #colB {
        margin: 0 163px; /*margins prevent under-wrap of side columns and
                           provide for a 9px gutter*/
        }
    Code (markup):
    Now the one running across the bottom,
    
    #footer {
        clear: both; /*this will naturally sit just under colC, but the clear
                       will ensure it goes below the longest column whichever
                       it is*/
        }
    Code (markup):
    Now to the html. Use a complete, strict DTD to trigger standards mode in all browsers. There's nothing good about each browser following its own set of rules; especially not IE.
    
    <div id="wrapper">
      <div id="colA">
        <p>Left hand column</p>
      </div>
    
      <div id="colC">
        <p>Right hand column</p>
      </div>
    
      <div id="colB">
        <p>center column</p>
      </div>
    
      <div id="footer">
        <p>stuff that goes under the three columns</p>
      </div>
    </div> <!-- end wrapper -->
    Code (markup):
    cheers,

    gary
     
    kk5st, May 15, 2006 IP
    goldensea80 likes this.
  6. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #6
    To: kk5st
    Sorry for late reply, 'cause I was busy doing the academic stuffs. Really thank what you've explained. The example is simple enough and it works! :D
     
    goldensea80, May 24, 2006 IP
  7. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #7
    I just noticed this typo
    
    #colB {
        margin: 0 163px; /*margins prevent under-wrap of side columns and
                           provide for a 9px gutter*/
        }
    Code (markup):
    The margin values should be "0 263px". Sorry if that caused anyone problems.

    cheers,

    gary
     
    kk5st, May 24, 2006 IP