How to make sidebar with same height as the content div?

前端 未结 5 1044
暗喜
暗喜 2021-01-19 08:37

the code is the following:

(CSS)

#container {
    border:1px dashed #000;
    overflow:hidden;
}
#content, #sidebar {
    float:left;
    width:50%;
         


        
相关标签:
5条回答
  • 2021-01-19 09:27

    You can do that by displaying the #container as table and displaying #content and #sidebar as table-cells:

    #container {
        border:1px dashed #000;
        display: table;
        width: 100%;
    }
    #content, #sidebar {
        display: table-cell;
        width:50%;
    }
    

    Check your updated Fiddle.

    0 讨论(0)
  • 2021-01-19 09:35
    .table {
        display:table;
    }
    .row {
        display:table-row;
    }
    .one {
        width:200px;
        border:1px solid #333;
        display:table-cell
    }
    
    <div class="table">
        <div class="row">
            <div class="one">gfhgfhgfhgf</div>
            <div class="one">gfhgfhgfhgf</div>
        </div>
    </div>
    
    0 讨论(0)
  • 2021-01-19 09:36

    You can also try below code

    CSS goes here

    #container {
        border:1px dashed #000;
        overflow:hidden;
    }
    #content, #sidebar {
        float:left;
        width:50%;
    }
    #content {
        background:yellow;
    }
    
    #sidebar {
        background:grey;
    }
    
    
    #Container
    {
        height: auto;
        width: auto;
    }
    

    and update HTML as follows,

    <div id="Container">
        <span id="content">
            <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
        </span>
    
        <span id="sidebar">
            <p>Few words</p>
        </span>
     </div>
    
    0 讨论(0)
  • 2021-01-19 09:40

    It can be solved with #content, #sidebar { display: table-cell; width:50%; }

    0 讨论(0)
  • 2021-01-19 09:40

    Just use this code before the container closing Div, works for me!

    <p style="clear:both;"></p>
    
    0 讨论(0)
提交回复
热议问题