How to do a `float: left` with no wrapping?

后端 未结 3 1752
孤城傲影
孤城傲影 2021-01-31 09:24

I have a container box1 that has a certain width (which might change depending on its content). That box contains box2 which has a fixed width (it coul

3条回答
  •  我在风中等你
    2021-01-31 09:53

    I'd recommend the following:

    #box1
    {
        position: relative; /* or some other positioned value */
    }
    
    #box2
    {
        width: 10px;
        height: 10px;
        position: absolute;
        top: 0;
        left: 0;
    }
    
    #box3
    {
        margin-left: 10px;
    }
    

    If #box2 is of a fixed size, you can simply use a margin for #box3 to prevent its overlapping of #box2, and since it's not positioned, #box1 will grow as #box3 grows.

提交回复
热议问题