/    Sign up×
Community /Pin to ProfileBookmark

column-like layout using div´s

Ok, this one shouldn´t be that difficult…
What I wanna do is a layout with two divs side-by-side, just like table columns. As I try to control everything via CSS I´d like to avoid setting up a real table structure in my html document. This is my html:

[CODE]

<body id=”contentpage”>

<div id=”content”>

<div id=”main”>
text
</div>

<div id=”right”>
supplementary information
</div>

</div>

</body>

[/CODE]

“main” is the place for most of the content, and it should adapt its width to the width of the browser window, whereas “right” has to stay fixed in width.
Both of them together musn´t take up more than a certain total width – that´s why I wrapped them into the “content” container.

The following are some of my tries to achieve a correct positioning of the elements:

[CODE]

#content {
max-width: 400px;
}

#main {
max-width: 300px;
}

#right {
float: right;
width: 100px;
}

[/CODE]

  • “right” div appears horizontally correct, but below “main” div and not to its right as intended

  • changing order of “right” and “main” divs in html document does the following: “right” div comes up but “main” content floats around it (I want a behaviour like real columns, however)

  • putting the “main” div before the “right” div in the html document and having the “main” div “float: right;” doesn´t do anything – “right” content appears below “main” text

  • IE5 and, more shockingly, IE6 ignore max-width altogether – are there other important browser issues I have to take care of in this context?
  • [CODE]

    #content {
    max-width: 400px;
    }

    #main {
    max-width: 300px;
    position: absolute;
    top: 0px;
    }

    #right {
    width: 100px;
    position: absolute;
    top: 0px;
    float: right;
    }

    [/CODE]

  • due to the absolute positioning, both divs and their content are laying over each other

  • if “right: 0px;” is added to the “right” div´s css, it will appear at the right side of the browser window and not at the right edge of the “content” div

  • changing order of “main” and “right” divs (because of the float attribute) in html document doesn´t help
  • So… how do I have to do it? I guess it´s just some small thing to change in order to get it working – but what exactly? It´s important to me to have a reliable solution with high browser compatibility, so if this is a problem here I´ll be grateful for different ways to do it…
    Thanks for your help!
    Toby

    to post a comment
    CSS

    5 Comments(s)

    Copy linkTweet thisAlerts:
    @FangSep 30.2004 — Is this the layout?

    max-width does not work in IE. I have add IE6 specific code to do the same.

    Considering the max-width:400px why not have a fixed width which would be supported by all (older) browsers.
    &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"&gt;
    &lt;html lang="en"&gt;
    &lt;head&gt;
    &lt;title&gt;Basic layout&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
    &lt;style type="text/css"&gt;
    &lt;!--
    * {margin:0;padding:0;}
    #content {border:1px solid red;
    position:relative;
    max-width:400px;
    width:expression(document.documentElement.clientWidth &gt; 400? "400px": "auto");
    }

    #main {border:1px solid blue;
    margin-right:100px;
    }

    #right {border:1px solid green;
    position:absolute;
    top:0;
    right:0;
    width: 100px;
    }
    --&gt;
    &lt;/style&gt;

    &lt;/head&gt;
    &lt;body&gt;
    &lt;div id="content"&gt;
    &lt;div id="main"&gt;
    &lt;h2&gt;main&lt;/h2&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus luctus quam quis tellus fermentum luctus.&lt;/p&gt;
    &lt;p&gt;Aliquam mauris nulla, pretium nec, volutpat egestas, gravida sed, turpis. Fusce rhoncus tempor elit. Nam ac mi.&lt;/p&gt;
    &lt;p&gt;Quisque imperdiet arcu. Sed pellentesque nisl in nunc. Proin sit amet augue nec turpis eleifend ultrices.&lt;/p&gt;
    &lt;p&gt;Aenean porta sodales mauris. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent porta diam non mi.&lt;/p&gt;
    &lt;/div&gt;
    &lt;div id="right"&gt;
    &lt;h2&gt;right&lt;/h2&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit.&lt;/p&gt;
    &lt;/div&gt;
    &lt;/div&gt;
    &lt;/body&gt;
    &lt;/html&gt;
    Copy linkTweet thisAlerts:
    @NogDogSep 30.2004 — This is the general format that I got to work (using a "repeat-y" background image for a "faux columns" effect):

    HTML:
    <i>
    </i>&lt;div class=container&gt;
    &lt;div class=right&gt;
    ...content...
    &lt;/div&gt;
    &lt;div class=main&gt;
    ...content...
    &lt;/div&gt;
    &lt;/div&gt;

    CSS:
    <i>
    </i>div.container {
    background-color: white;
    background-image: url(img/gray.png);
    background-repeat: repeat-y;
    background-position: right;
    width: 800px;
    top: 0;
    margin: 10px 0 0 0;
    margin-left: auto;
    margin-right: auto;
    }
    div.main {
    width: 480px;
    margin: 0;
    padding: 20px;
    background-color: transparent;
    color: #000033;
    float: left;
    clear: left;
    }
    div.right {
    font-size: smaller;
    width: 200px;
    margin: 20px;
    margin-right: 10px;
    padding: 20px;
    background-color: transparent;
    color: black;
    float: right;
    clear: right;
    }
    Copy linkTweet thisAlerts:
    @sir_tobyauthorSep 30.2004 — Sorry, but your snippet of IE6 specific code won´t change anything in my case... Sounds logical, though. Do I perhaps have to replace "documentElement" and adapt it to my own situation? This would explain things...

    Why is that code IE6 specific? Can´t it be understood by other browsers, and not even by IE5? I don´t see any reason for this.

    Thanks anyway,

    Toby
    Copy linkTweet thisAlerts:
    @FangSep 30.2004 — If you want to use max-width, which IE and older browsers don't understand then a bit of IE specific code will help.

    You haven't mentioned if any of the solutions offered are to your requirements.
    Copy linkTweet thisAlerts:
    @ShmohelSep 30.2004 — http://glish.com/css/7.asp

    here is a great 3 column layout
    ×

    Success!

    Help @sir_toby spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.24,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...