How to make a div fill a remaining horizontal space?

前端 未结 25 1463
野的像风
野的像风 2020-11-22 00:45

I have 2 divs: one in the left side and one in the right side of my page. The one in the left side has fixed width and I want the one of the right side to f

25条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 01:35

    I had a similar issue and came up with the following which worked well

    CSS:

    .top {
    width: auto;
    height: 100px;
    background-color: black;
    border: solid 2px purple;
    overflow: hidden;
    }
    .left {
    float:left;
    width:100px;
    background-color:#ff0000;
    padding: 10px;
    border: solid 2px black;
    }
    .right {
    width: auto;
    background-color:#00FF00;
    padding: 10px;
    border: solid 2px orange;
    overflow: hidden;
    }
    .content {
    margin: auto;
    width: 300px;
    min-height: 300px;
    padding: 10px;
    border: dotted 2px gray;
    }
    

    HTML:

    top
    left
    right

    This method won't wrap when the window is shrunk but will auto expand the 'content' area. It will keep a static width for the site menu (left).

    And for auto expanding content box and left vertical box(site menu) demo:

    https://jsfiddle.net/tidan/332a6qte/

提交回复
热议问题