How do I float two divs side-by-side without specifying a width?

前端 未结 3 1912
孤独总比滥情好
孤独总比滥情好 2021-01-31 21:38

I have two divs, the first doesn\'t have much content and the second has a lot of content. I want them to float side-by-side such that the first div is only as wide as the text

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 21:54

    Yes, you can do it with css & it's work in all browsers. Do like this:

    .right{
        overflow:hidden;
        background:red;
    }
    .left{
        float:left;
        background:green;
    }
    

    Check this live example http://jsfiddle.net/enRkR/8/

提交回复
热议问题