Expand container div with content width

前端 未结 6 384
逝去的感伤
逝去的感伤 2020-12-24 10:40

I have the following structure in my application:

相关标签:
6条回答
  • 2020-12-24 11:27

    just set the width of the parent to 120% and done =)

    0 讨论(0)
  • 2020-12-24 11:33

    Something like this should work:

    #container, #child_container, .child { 
        position: relative; 
        float: left;
    }
    
    0 讨论(0)
  • 2020-12-24 11:34

    If you float everything left including the containing divs, it will work.

    0 讨论(0)
  • 2020-12-24 11:36

    The parent container won't grow when a child element is added.

    +------ container -------+
    +--- child_container ----+
    | child1 child2 child3   |
    | child4                 |
    +------------------------+
    

    but we can avoid the rendering of new one on the next line by using css3 flex box. The sample is placed the below mentioned path

      .products{
                display: -webkit-flex;
                -webkit-flex-flow: row;
                /*-webkit-justify-content: center;*/
            }
            .products > div{
                padding: 0 4em;
            }
    

    The result will look like this:

    +--- child_container ----+|
    | child1 child2 child3  ch|ild4 child5  
    |                         |
    +------------------------+
    
    0 讨论(0)
  • 2020-12-24 11:41

    Even easier:

    <style>
        #container{ display: inline-block; }
    </style>
    
    0 讨论(0)
  • 2020-12-24 11:43

    The modern solution today would be

    #child_container {
        display: flex;
    }
    

    Because flex-wrap is by default set to

    flex-wrap: nowrap;
    

    This simple solution works like a charm. And by now also in all relevant browsers.

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