How to force child div to be 100% of parent div's height without specifying parent's height?

前端 未结 26 2047
刺人心
刺人心 2020-11-22 06:52

I have a site with the following structure:

<
26条回答
  •  日久生厌
    2020-11-22 07:37

    I know it's been a looong time since the question was made, but I found an easy solution and thought someone could use it (sorry about the poor english). Here it goes:

    CSS

    .main, .sidebar {
        float: none;
        padding: 20px;
        vertical-align: top;
    }
    .container {
        display: table;
    }
    .main {
        width: 400px;
        background-color: LightSlateGrey;
        display: table-cell;
    }
    .sidebar {
        width: 200px;
        display: table-cell;
        background-color: Tomato;
    }
    

    HTML

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam congue, tortor in mattis mattis, arcu erat pharetra orci, at vestibulum lorem ante a felis. Integer sit amet est ac elit vulputate lobortis. Vestibulum in ipsum nulla. Aenean erat elit, lacinia sit amet adipiscing quis, aliquet at erat. Vivamus massa sem, cursus vel semper non, dictum vitae mi. Donec sed bibendum ante.

    Simple example. Note that you can turn into responsiveness.

提交回复
热议问题