Justplayit94
Justplayit94

Reputation: 423

Div Resive To Fit Text

This is not necessary to get an answer, but it's more of a problem I've encountered. Let's say I have a piece of text and I want that the div element that contains it to resize it width property proportionally to the amount of text. Is there a elegant way to do so? I've read about min-width, but doesn't work in my case.

Upvotes: 0

Views: 120

Answers (2)

mac
mac

Reputation: 858

You may be able to implement a pure CSS solution if you have a target width/height ratio in mind. Take a look at this previous post on the subject.

The trick is to add a parent <div> with padding-bottom applied.

Upvotes: 0

bboysupaman
bboysupaman

Reputation: 1334

Text typically flows to fill it's container. I don't think CSS is going to be the best way to accomplish this. The very concept is too dynamic for the limitations of CSS. The best way that I can think to do this would be to use javascript to adjust the width of the div based on the length of the string contained within.

Upvotes: 2

Related Questions