Child div 100% height to parent auto height

后端 未结 7 1120
孤城傲影
孤城傲影 2021-02-12 19:50

Im here because other similar questions couldn\'t help my particular problem.

I need right div to be 100% height all the time, where the parent

相关标签:
7条回答
  • 2021-02-12 20:28

    You can accomplish this using flexbox and some creativity.

    .container {
      display: flex;
      background: black;
      padding: 5px;
      width: 300px
    }
    
    .left {
      height: 200px;
      flex: 1 0 0px;
      background: blue;
    }
    
    .right {
      flex: 1 0 0px;
      overflow: auto;
      background: green;
    }
    
    .column {
      display: flex;
      flex-direction: column;
      width: 20%;
    }
    <div class="container">
      <div class="left"></div>
      <div class="column">
        <div class="right"></div>
      </div>
    </div>

    0 讨论(0)
  • 2021-02-12 20:36

    .parent{
        position: relative;
        width: 100px;
        height: auto;
    }
    .child{
        width: 50px;
        height: 100px;
        background-color: red;
    }
    .child_absolute{
        position: absolute;
        left: 50px;
        top: 0;
        bottom: 0;
        width: 50px;
        background-color: blue;
    }
    <div class="parent">
        <div class="child"></div>
        <div class="child_absolute"></div>
    </div>

    0 讨论(0)
  • 2021-02-12 20:45

    By reading your comments on other solutions it is clear to me that only solution for you is to implement some JS into your code. This is not a problem, however.

    http://jsfiddle.net/b7TuP/

    0 讨论(0)
  • 2021-02-12 20:45

    You can use the table-cell value of the display property in this layout and remove the float like this:

    .left, .right{
        display:table-cell;
    }
    

    live demo http://jsfiddle.net/C9Kmx/34/

    0 讨论(0)
  • 2021-02-12 20:46

    Make the right div position:absolute; and make the parent div position:relative; and then height:100%; will work for the right div. Make sure you also adjust its x-position and width accordingly. In this example I gave it a left:50px to make sure it appears to the right of the left column.

    JSFiddle http://jsfiddle.net/e9mvD/

    0 讨论(0)
  • 2021-02-12 20:46

    Give position:fixed and height:100% for the right div. This will solve your issue.

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