Expand a div to fill the remaining width

前端 未结 21 1204
一生所求
一生所求 2020-11-21 22:21

I want a two-column div layout, where each one can have variable width e.g.

相关标签:
21条回答
  • 2020-11-21 22:56

    A slightly different implementation,

    Two div panels(content+extra), side by side, content panel expands if extra panel is not present.

    jsfiddle: http://jsfiddle.net/qLTMf/1722/

    0 讨论(0)
  • 2020-11-21 22:56

    Thanks for the plug of Simpl.css!

    remember to wrap all your columns in ColumnWrapper like so.

    <div class="ColumnWrapper">
        <div class="Colum­nOne­Half">Tree</div>
        <div class="Colum­nOne­Half">View</div>
    </div>
    

    I am about to release version 1.0 of Simpl.css so help spread the word!

    0 讨论(0)
  • 2020-11-21 22:59

    Check this solution out

    .container {
      width: 100%;
      height: 200px;
      background-color: green;
    }
    .sidebar {
      float: left;
      width: 200px;
      height: 200px;
      background-color: yellow;
    }
    .content {
      background-color: red;
      height: 200px;
      width: auto;
      margin-left: 200px;
    }
    .item {
      width: 25%;
      background-color: blue;
      float: left;
      color: white;
    }
    .clearfix {
      clear: both;
    }
    <div class="container">
      <div class="clearfix"></div>
      <div class="sidebar">width: 200px</div>
    
      <div class="content">
        <div class="item">25%</div>
        <div class="item">25%</div>
        <div class="item">25%</div>
        <div class="item">25%</div>
      </div>
    </div>

    0 讨论(0)
  • 2020-11-21 23:00

    Im not sure if this is the answer you are expecting but, why don't you set the width of Tree to 'auto' and width of 'View' to 100% ?

    0 讨论(0)
  • 2020-11-21 23:02

    I just discovered the magic of flex boxes (display: flex). Try this:

    <style>
      #box {
        display: flex;
      }
      #b {
        flex-grow: 100;
        border: 1px solid green;
      }
    </style>
    <div id='box'>
     <div id='a'>Tree</div>
     <div id='b'>View</div>
    </div>
    

    Flex boxes give me the control I've wished css had for 15 years. Its finally here! More info: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

    0 讨论(0)
  • 2020-11-21 23:02

    You can try CSS Grid Layout.

    dl {
      display: grid;
      grid-template-columns: max-content auto;
    }
    
    dt {
      grid-column: 1;
    }
    
    dd {
      grid-column: 2;
      margin: 0;
      background-color: #ccc;
    }
    <dl>
      <dt>lorem ipsum</dt>
      <dd>dolor sit amet</dd>
      <dt>carpe</dt>
      <dd>diem</dd>
    </dl>

    0 讨论(0)
提交回复
热议问题