2 divs aligned side by side, how to make right div fill width 100%?

前端 未结 8 1057
遥遥无期
遥遥无期 2021-01-31 08:17

I\'m wondering what the best way to go about doing this is...

I have 3 divs:

  • a div#container with width=100%; tha

相关标签:
8条回答
  • 2021-01-31 08:42

    This is based on @w00 's answer. +1 friend.

    My situation was when I wanted to show a couple of icons next to a label. I use the fluid class for that which is where the nowrap comes in. This is so the icons appear on the same line.

    .sidebyside-left-fixed, .sidebyside-right-fixed
    {
        display: table-cell;
        width: 100%;
    }
    
    .sidebyside-left-fluid , .sidebyside-right-fluid
    {
        display: table-cell;
        vertical-align: top;
        white-space: nowrap;
    }
    
    0 讨论(0)
  • 2021-01-31 08:54

    Have a look at "liquid layouts" it can describe what you're talking about.

    You're probably looking for this one.

    In your example, try setting your display to inline. However, you won't technically be able to use block level elements in it, so have a look at the links I posted above. :)

    The problem with setting the width to 100% if you're using floats is that it is considered 100% of the container, so it won't work either since the 100% includes the left div's width.

    Edit: Here is the example of the other answer, I've edited it to include the html/css from the example site above for simplicity's sake.

    I'll also include it below:

    HTML

    <div id="contentwrapper">
        <div id="contentcolumn">
            <div class="innertube"><b>Content Column: <em>Fluid</em></b></div>
        </div>
    </div>
    <div id="leftcolumn">
        <div class="innertube"><b>Left Column: <em>200px</em></b></div>
    </div>
    

    CSS

    #contentwrapper{
    float: left;
    width: 100%;
    }
    
    #contentcolumn{
    margin-left: 200px; /*Set left margin to LeftColumnWidth*/
    }
    
    #leftcolumn{
    float: left;
    width: 200px; /*Width of left column*/
    margin-left: -100%;
    background: #C8FC98;
    }
    
    0 讨论(0)
提交回复
热议问题