Overflowing a container div horizontally but not vertically

后端 未结 2 637
半阙折子戏
半阙折子戏 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: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

    left 1st inner panel
    left 2nd inner panel
    right 1st inner panel
    right 2nd inner panel with arbitrary text to show the increase in parent elements

    view demo

提交回复
热议问题