Nils Ziehn
Nils Ziehn

Reputation: 4331

prevent div resizing because of inner text

Here is my code:

<div>
  <table>
    <tr><td>
      <img ...>
    </td></tr>
    <tr><td>
      <p style="text-overflow: ellipsis;white-space: nowrap;">HERE MAY BE SONE VERY LONG TEST!!!</p>
    </td></tr>
  </table>
</div>

I want the width of my div as wide as my image, but since I don't know how wide my image is, I can't specify a width for the p to keep it in bounds.

I am looking for an html(+css) only solution, if there is any. I know how I could accomplish this in js, but that gets messy since the image size is changed over time.

Is there a way to do this in pure html/css?

Upvotes: 1

Views: 246

Answers (1)

Danield
Danield

Reputation: 125473

You could simply set the width of the table to be very small:

FIDDLE

table
{
    width: 1px;
}

Upvotes: 1

Related Questions