DIVs Arrangement - HTML CSS

后端 未结 3 1720
孤城傲影
孤城傲影 2021-01-29 08:07

\"Arrangement\"

How can i construct above arrangement without using js ?

Thanks in advance !



        
相关标签:
3条回答
  • 2021-01-29 08:52

    If the width of #div1 is fixed at 150px and #div3 is dynamic, then you can use :

    #div2 {
        width : calc(100% - 150px);
    }
    

    And if #div1 is also dynamic, then you need to use JS.

    0 讨论(0)
  • 2021-01-29 08:56

    all of those techniques in the other answers have a common problem. they are assuming that the width of the first column is 150px, but actually you need min-width to be 150px. so what happens when the first column need to grow?

    take a look at my solution. pure CSS, without using calc (so its also supported in older browsers like IE8)

    Working Fiddle

    HTML: nothing new here..

    <div id="Container">
        <div id="Column1">content</div>
        <div id="Column2">content of second div is very  very large</div>
    </div>
    

    CSS:

    #Container
    {
        width: 80%; /*Change to WTE you want*/
        display: table;
        border: 1px solid black;
        margin: 0 auto;
    }
    #Container > div
    {
        display: table-cell;
    }
    #Column1
    {
        background-color: red;
        min-width: 150px; /*From your CSS*/
    }
    
    #Column2
    {
        background-color: green;
    }
    
    0 讨论(0)
  • 2021-01-29 08:59

    You could use the holy grail technique: http://alistapart.com/article/holygrail

    #div3 {
        display: block;
        background: blue;
        padding-left: 150px;
    }
    
    #div1 {
        width: 150px;
        float: left;
        margin-left: -150px;
    }
    
    #div2 {
        width: 100%;
        float: left;
    }
    

    What this does is create a 150px wide padding on the left of #div3, but it pulls #div1 into it with the negative margin.

    This way the "100%" that #div2 uses is actually (100% - 150px) of #div3

    0 讨论(0)
提交回复
热议问题