height 100% doesn't work, two divs inside div

后端 未结 8 1573
伪装坚强ぢ
伪装坚强ぢ 2021-01-22 19:45

See css: http://jsfiddle.net/4JgA4/114/

Also here:

8条回答
  •  广开言路
    2021-01-22 20:28

    as stated in other answers, the 100% don't work unless the parent height is also specified.

    looks like you are trying to achieve 'equal column height', you don't have to set the parent height for that. using CSS table layout can be helpful here.

    notice how clean this styling is. no floating elements, and no need to specify the same height again and again in different elements.

    look at this Fiddle

    best practice: separate your styling from your markup.

    HTML:

    First to set height
    Why don't get the 100%

    CSS:

    #Parent
    {
        display: table;
    }
    #Parent > div
    {
        display: table-cell;
        border: 1px solid black;
    }
    #Parent > div:first-child /*if you want to fixed the first column height*/
    {
        height: 150px; /*or any other fixed height you want*/
    }
    

提交回复
热议问题