How can I make a div not larger than its contents?

前端 未结 30 3626
青春惊慌失措
青春惊慌失措 2020-11-21 07:35

I have a layout similar to:

I would like for the div to only exp

30条回答
  •  盖世英雄少女心
    2020-11-21 08:07

    A CSS2 compatible solution is to use:

    .my-div
    {
        min-width: 100px;
    }
    

    You can also float your div which will force it as small as possible, but you'll need to use a clearfix if anything inside your div is floating:

    .my-div
    {
        float: left;
    }
    

提交回复
热议问题