1

I have a div with an img and a p tag. I want the div to "shrink-wrap" the image and let the text organically wrap. However, I'm trying to do this with absolutely no javascript or constraints (ie width=300px / 50% etc) as my frame needs to be fluid.

Here's an example of something similar to what I have now: How can I make the outer dive match the size of the "Google" image without using fixed sizes or javascript?

http://jsfiddle.net/pVF74/

3

2 Answers 2

4
div {
    border:1px solid black;
    display:table;
    width:1%;
}

http://jsfiddle.net/pVF74/2/

1
  • What is the reason for the 1%?
    – kmindspark
    Aug 29, 2020 at 22:01
1

Add display: inline-block; to your div's class.

Example here http://jsfiddle.net/r9rLr/

5
  • What does this change?
    – scrblnrd3
    Dec 18, 2013 at 15:27
  • 1
    Doesn't change a thing.
    – j08691
    Dec 18, 2013 at 15:27
  • You might be viewing this in a small window. Make sure your "Result" window is larger than the image.
    – Jacksonkr
    Dec 18, 2013 at 15:28
  • @scrblnrd3 - no, it doesn't. At least not in Chrome.
    – j08691
    Dec 18, 2013 at 15:30
  • i've seen this for quite a bit of answers. Both it and the accepted answer don't help me out. Just wanted to state that. I'm still searching...
    – dogonaroof
    Mar 5, 2019 at 11:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.