Two divs, one fixed width, the other, the rest

前端 未结 10 1187
死守一世寂寞
死守一世寂寞 2020-11-27 11:28

I\'ve got two div containers.

Whilst one needs to be a specific width, I need to adjust it, so that, the other div takes up the rest of the space. Is there any way I

10条回答
  •  粉色の甜心
    2020-11-27 12:11

    If you can flip the order in the source code, you can do it like this:

    HTML:

    // needs to be 250px

    CSS:

    .right {
      width: 250px;
      float: right;
    }   
    

    An example: http://jsfiddle.net/blineberry/VHcPT/

    Add a container and you can do it with your current source code order and absolute positioning:

    HTML:

    CSS:

    #container {
      /* set a width %, ems, px, whatever */
      position: relative;
    }
    
    .left {
      position: absolute;
      top: 0;
      left: 0;
      right: 250px;
    }
    
    .right {
      position: absolute;
      background: red;
      width: 250px;
      top: 0;
      right: 0;
    }
    

    Here, the .left div gets an implicitly set width from the top, left, and right styles that allows it to fill the remaining space in #container.

    Example: http://jsfiddle.net/blineberry/VHcPT/3/

提交回复
热议问题