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

前端 未结 30 3715
青春惊慌失措
青春惊慌失措 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:12

    Revised (works if you have multiple children): You can use jQuery (Look at the JSFiddle link)

    var d= $('div');
    var w;
    
    
    d.children().each(function(){
     w = w + $(this).outerWidth();
     d.css('width', w + 'px')
    });
    

    Do not forget to include the jQuery...

    See the JSfiddle here

提交回复
热议问题