SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: CSS - a simple float problem ?

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CSS - a simple float problem ?

    I thought this would be simple, but it has exceeded my limited knowloedge of CSS.

    Basically, I'm trying to convert this into CSS so I don't need to use tables:

    Code:
    <table>
      <tr>
        <td width="850px">
          850 wide object goes here
        </td>
        <td width="*">
          Explanatory text goes here, this text only includes <p /> where necessary
        </td>
      </tr>
    </table>
    So basically I (think I) need two DIVs side by side the first one can have a hardcoded width, but I'd like the second one to take the remaining screen real estate on the right and display the text

    I have got to the point where I can get them side by side, but only by including <br /> all over the place which looks good on my screen, but not others.

    Please help ....

  2. #2
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at http://www.pmob.co.uk/temp/3colfixedtest_4.htm, you will learn everything you need to know about column layouts.

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That will take a bit of reading, but it seems to be what I'm after

    Thank you

  4. #4
    Ripe Tomatos silver trophybronze trophy Rayzur's Avatar
    Join Date
    Jun 2007
    Location
    Texas
    Posts
    4,174
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    You can get a quick crash course on floats at the Floatutorial.

    For one thing floated items must have a width declared on them, as per your example you would only be floating the div that has 850px set on it.

    Here is what you have described, it is an example only. Not to be used as a layout yet.

    demo.html
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled</title>
    <meta name="generator" content="PSPad editor, www.pspad.com">
    <style type="text/css">
    * {margin:0; padding:0;} 
    body {
        background: #dcdcdc;
    }
    h1,h2,h3,p {padding:10px}
    #wrapper {
        margin:auto;
        width: 99.8&#37;;
        min-width:1050px;
        background: skyblue;
        border:1px solid black;
    }
    #header {
        position:relative;
        height:100px;
        background: #6bb;
        border-bottom:1px solid black;
        text-align:center;
        clear:both;
    }
    #innerwrap {
        width:100%;
    }
    #content {
        position:relative;
        float:left;
        width: 850px;
        min-height:500px;
        background:wheat ;
        border-right:1px solid black;
    }
    #right {
        position:relative;
        background:inherit;
        min-height:500px;
        padding-left:850px;
    }
    * html #content, #right {height:500px;}
    
    </style>
    </head>
    <body>
    <div id="wrapper">
    <div id="header">
    <h2>Header</h2>
    </div>
        <div id="innerwrap">
        <div id="content">
            <p>850 wide object goes here</p>
            <p>This content div is floated left</p>
        </div>
        <div id="right">
            <p>Explanatory text goes here, this text only includes where necessary</p>
            <p>This text is set in the innerwrap div.</p>
            <p>This div does not have a float set on it, so there is no need to declare a width.
            It will size down in width with the browser.</p>
        </div>
        </div><!--end innerwrap-->
    </div><!--end wrapper-->
    </body>
    </html>
    This is an example of two divs floated left and right. They have widths set on them.
    demo-2.html

    Code:
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled</title>
    <meta name="generator" content="PSPad editor, www.pspad.com">
    <style type="text/css">
    * {margin:0; padding:0;} 
    body {
        background: #dcdcdc;
    }
    h1,h2,h3,p {padding:10px}
    #wrapper {
        margin: 0 auto;
        width: 1050px;
        background: skyblue;
        border:1px solid black;
    }
    #header {
        position:relative;
        height:100px;
        background: #6bb;
        border-bottom:1px solid black;
        text-align:center;
        clear:both;
    }
    #content {
        position:relative;
        float:left;
        width: 850px;
        min-height:300px;
        background: inherit;
        border-right:1px solid black;
        display:inline;
    }
    #right {
        position:relative;
        float:right;
        width:199px;
        min-height: 300px;
        background: wheat;
        display:inline;
    }
    * html #right {margin-left:-3px;}
    * html #right, #content {height:300px;}
    .clear { clear: both;}
    </style>
    </head>
    <body>
    <div id="wrapper">
    <div id="header">
    <h2>Header</h2>
    </div>
        <div id="content">
            <p>850 wide object goes here</p>
        </div>
        <div id="right">
            <p>Explanatory text goes here, this text only includes where necessary</p>
            <p>This floated div is set at a width of 199px, if you remove the width
            it will fall and find room for the longest set of text.</p>
        </div>
        <div class="clear"></div>
    </div><!--end wrapper-->
    </body>
    </html>

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
  •