Search code examples
csspositionpositioning

CSS: Is it possible to have a 3-column layout with BOTH the left column and center column flexibly filling the space?


It is possible to use position:absolute and left and right on the middle column to set where it ends in relation to the parent div.

However I'd like to be able to have the left side of the center div to start right where the left column ends, and for the left column to be adjustable (based on its content).

This seems like a really basic thing but from what I understand there is no way to do this without flexboxes. Is this true? Is there nothing I could do with clever nesting of semantically superfluous elements and certain styles set to auto?


Solution

  • If the right div has some set width (either in % or px), then yes, you can let the left div's width be defined by its content while letting the center div fill in the remaining space:

    #right {
      position: absolute; /* position in top right corner */
      top: 0;
      right: 0;
      width: 80px;
    }
    #center {
      margin-right: 80px; /* same as #right width */
    }
    #left {
      float: left;
    }
    

    jsFiddle DEMO