Auto Div height depend on another one

后端 未结 3 1572
你的背包
你的背包 2021-01-15 12:09

I have the following scenario I want Div2 height to resize depend on the content of Div3 how I can do that ?

----------------------------------
.      DIV1          


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-15 12:27

    I think you want to display same height of both DIV2 and DIV3. By CSS you can do it as below:

    HTML

    First Div content goes here
    Second Div content goes here

    CSS

    .wrapper {
            width: 960px;
            overflow: hidden;
            margin: 0px auto;
        }
    
        .child_1, .child_2 {
            padding-bottom: 1000px;
            margin-bottom: -1000px;
            width: 50%;
            float: left;
        }
    
        .child_1 {
            background: #f00;
        }
    
        .child_2 {
            background: #0f0;
        }
    

    Code above will display your div height's equal if they have 1000px different in height as per code. you can change 1000px, if you think in some case difference could be more. It'll support in all browsers

    Other wise you can use javascript for it. You need to find height of longest div and set same height in other div.

提交回复
热议问题