Three Column Layout side columns elastic middle fixed

后端 未结 2 2059
一生所求
一生所求 2021-01-29 06:16

I was wondering if anyone knows how to have a fixed width of the centered div and have the right and left div elastic on either side of the centered div. The centered div has a

相关标签:
2条回答
  • 2021-01-29 06:58

    I did it with flexbox, but can't do it with table-cell becouse side columns width depends on side column content. So my code looks like

    https://codepen.io/ArunsKas/pen/owveer

    HTML

    <div class="flex">
      <div class="flex-children">asdaaa asdaaaasdaaa asdaaa asdaaa</div>
      <div class="flex-children-fixed">
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora et nisi harum eaque quas similique esse voluptas? Expedita in vitae, vel unde deleniti hic dolores rerum. Aliquam quos quidem quae.</p>
      </div>
      <div class="flex-children">ddey</div>
    </div>
    

    CSS

    * {
      margin: 0;
      padding: 0;
    }
    .flex {
      display: flex;
      justify-content: space-between;
    }
    .flex-children {
      width: calc((100% - 200px)/2 - 10px);
      background: red;
    }
    .flex-children-fixed {
      width: 200px;
      background: red;
    }
    
    0 讨论(0)
  • 2021-01-29 07:18

    Try to add the code what you tried when you post a question.

    HTML

    <div class = "container">
        <div class = "fluid">
            I am fluid
        </div>
    
        <div class = "fixed">
            I'm Fixed! 
        </div>
    
        <div class = "fluid">        
            I am fluid
        </div>
    </div>
    

    CSS

    html, body {
        height: 100%;
        font-family: 'Arial', 'Helvetica', Sans-Serif;
    }
    .container {
        display: table;
        width: 100%;
        height: 100%;
    }
    .container > div {
        display: table-cell;
        text-align: center;
    }
    .fixed {
        min-width: 200px; max-width:300px;
        background: rgb(34, 177, 77);
        color: white;
    }
    .fluid {
        background: rgb(0, 162, 232);
    }
    ​
    

    DEMO LINK

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