How to place div side by side

前端 未结 7 1914
时光说笑
时光说笑 2020-11-22 15:47

I have a main wrapper div that is set 100% width. Inside that i would like to have two divs, one that is fixed width and the other that fills the rest of the space. How do i

7条回答
  •  清歌不尽
    2020-11-22 16:40

    If you're not tagetting IE6, then float the second

    and give it a margin equal to (or maybe a little bigger than) the first
    's fixed width.

    HTML:

    lorem ipsum
    dolor sit amet

    CSS:

    #main-wrapper {
        100%;
        background:red;
    }
    #fixed-width {
        width:100px;
        float:left
    }
    #rest-of-space {
        margin-left:101px;
            /* May have to increase depending on borders and margin of the fixd width div*/
        background:blue;
    }
    

    The margin accounts for the possibility that the 'rest-of-space'

    may contain more content than the 'fixed-width'
    .

    Don't give the fixed width one a background; if you need to visibly see these as different 'columns' then use the Faux Columns trick.

提交回复
热议问题