Overflowing a container div horizontally but not vertically

后端 未结 2 632
半阙折子戏
半阙折子戏 2021-01-20 05:40

I\'m working on a website that uses two columns inside a container. The container has a white background that should stretch to the bottom of whichever column is highest, so

相关标签:
2条回答
  • 2021-01-20 06:14

    The easiest fix in this case seems to be adding <br style="clear:both" /> before the closing tag for #container.

    You can change it to <br class="clearfix" /> and .clearfix{clear:both} if you wish.

    0 讨论(0)
  • 2021-01-20 06:30

    Solution is to use inline-block elements..

    Css

    .container{
        width:300px;
        background-color:#ccc;
        margin:0 auto;
        border:1px solid red;
    }
    .container > div{
        width:150px;
        display:inline-block;
        vertical-align:top;
    }
    .inner{
        background-color:#666;
        margin-top:10px;
        width:130px;
    }
    .left .inner{
        margin-left:-10px;
    }
    .right .inner{
        margin-right:-10px;
        margin-left:auto;
    }
    

    HTML

    <div class="container">
        <div class="left">
            <div class="inner">left 1st inner panel</div>
            <div class="inner">left 2nd inner panel</div>
        </div><div class="right">
            <div class="inner">right 1st inner panel</div>
            <div class="inner">right 2nd inner panel with arbitrary text to show the increase in parent elements</div>
        </div>
    </div>
    

    view demo

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