Shrink-to-fit div and paragraph, based on image?

前端 未结 6 1339
情歌与酒
情歌与酒 2020-12-11 16:27

The code below is a simplified version of my website. On my site, the image width varies from page to page and the text is around 100 words. That means the paragraph stretch

6条回答
  •  情歌与酒
    2020-12-11 16:59

    I recommend adding in a little jquery.. to make your life so much easier:

    imgw = $("img").width();
    $("div").css("width", imgw);
    

    Here is how it would look: http://jsfiddle.net/WM6hK/2/

    This way you can add this simple line of code to any div and just replace $("div") with and ID $("#idofdiv"). Hope this helps!

提交回复
热议问题