CSS: how to layout 3 columns, 2 are optional

Tags: css

Problem :

Say I have something like this:

<div id="content">
   <div id="main_content"></div>
   <div id="profile_sidebar"></div>
   <div id="sidebar"></div>

I want the content to appear in the follow order (left to right): profile_sidebar, main_content, sidebar. I'm trying to float:left profile_sidebar and float:right sidebar -- but it's not showing up as I hope.

Also, profile_sidebar and sidebar are both optional. They may not appear on the page.

UPDATE 1: I've updated the content to be like this:

<div id="content">
   <div id="profile_sidebar"></div>
   <div id="main_content"></div>
   <div id="sidebar"></div>

Solution :

I don't believe you can achieve this using just floats without changing the structure, but then it's easy. I imagine that's not an option?

Edit This illustrates jmbertucci's position:absolute work-around, and the potential problem.

    CSS Howto..

    How to make last element in a series of wrapped inline-block elements fill the available horizontal space?

    CSS - How to force elements to 100% of remaining/available space of parent element without extending beyond it?

    How to grey out a box in CSS

    How to make round corners to both inside of a box and its border?

    html element h1 with links as background image show them in one line

    HTML Table Header isn't showing, how can it be fixed?

    How to apply my class from css to checkbox? [duplicate]

    how can i center the text inside my css div circle

    how to set size of canvas to its background image?

    how to add css background color for div tag

    Using CSS, how can I make my document expand to the user's viewport if the content doesn't scroll?

    How to share common css and other resources among grails projects?

    How can I disable the color defined in an previously defined CSS class

    How do I add transition to the effect of hide() and show() on these elements?

    jQuery - How to get elements height value and use it in another element via css code?

    how to give dynamic height in css

    CSS only - how to have a scrolling ul with all li on one line

    Javascript: Hover over Issues & How can I structure the html efficiently?

    How to change css style for only one image in specific page in wordpress?

    How to align links on top of each other inside of a box with CSS?

    How to center navbar elements vertically (Twitter Bootstrap)?

    How to cut divs both ways to keep the objects in center?

    How do device screen resolutions scale in CSS?

    How to force floating blocks staying in the same row in css?

    How to create a Page Header (an Image) for print using css

    How to include Glyphicons without using Bootstrap CSS

    how to modify height of a div when hover it and with transition (priority of CSS without Javascript)

    how to control the css rotation of an element inside a rotated element?

    How to get the kendo NumericalTextBox to share the width of a table cell the same way the kendo DropDownList does?

    How to style a randomly generated list of items in Javascript