Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make content fit to the width of the div

Tags:

html

css

How can I make a text fit to the width of div. Here is my code

<div class="column">
    <a href="#" class="user_thumbnail">
        <img src="<?=base_url()?>/images/1.jpg" width="100px" height="100px">

    </a>
    <span class="name">texttexttexttexttexttexttexttexttexttext</span>
</div>

When I have tried to display the text, the text overflows out of the div like a straight line. How can i do css to fit the text to the width of <div class="column"> (width = 33%).

like image 750
VeNaToR Avatar asked Aug 01 '13 12:08

VeNaToR


People also ask

How do I make div width fit to content?

There are three ways to solve this problem which are listed below: By default case. Using inline-block property. Using fit-content property in width and height.

How do I make a div fit in a div?

For width it's easy, simply remove the width: 100% rule. By default, the div will stretch to fit the parent container.

What is width fit-content?

In a few words width: fit-content; means : "Use the space you can (available) but never less than your min-content and never more than your max-content "


2 Answers

word-wrap:break-word

  • Wrap long words onto the next line.
  • Adjust different words so that they do not break in the middle.

So try the below CSS

.column {
    width: 33%;
    word-wrap: break-word;
}

JSFiddle

like image 189
Praveen Avatar answered Sep 24 '22 12:09

Praveen


You can use word-break: break-all; (assuming you meant fit the width of the div, not the height like your title says)

.column {
    width: 33%;
    word-break: break-all;
}

http://jsfiddle.net/VbTes/1/

like image 28
Adrift Avatar answered Sep 21 '22 12:09

Adrift