Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap text to max-width in an absolute position container

Tags:

html

css

I am building an absolute position container with some texts, max-width is 200px, so text should wrap until 200px, but it's not working.

I can not set a fixed width because should be smaller if text is shorter.

Container has a relative position parent with "display: inline;" style, (this style is causing the problem).

How can I make the container fill the 200px if text is longer?

This is the fiddle: https://jsfiddle.net/m2wr9m06/3/

.showlist {
    box-shadow: 5px 5px 20px #191919;
    padding: 5px;
    max-width: 200px;
    position: absolute;
    z-index: 1;
    left: -5px;
    font-family: "Century Gothic", Century, "Arial Black";
    font-size: 14px;
}
.flag {
    color: #FF9900;
    position: relative;
    display: inline-block; /* remove this rule to see the expected result */
    margin: 5px;
    font-size: 16px;
}
<div class="flag">
  <div class="showlist" >
    <div>asdf 4444 555555 666666 7 8 8888 9999 555 444</div>
    <div>4 8 15 16 23 42</div>
    <div>asdf foo bar </div>
  </div>
</div>

(remove "dispay:inline;" rule to see the expected result)

like image 297
stramin Avatar asked Nov 09 '22 15:11

stramin


1 Answers

I found a solution, I hope it helps someone, I added an extra container with 200px; width:

<div class="flag">
<div style='width:200px;'>
  <div class="showlist" >
    <div>asdf 4444 555555 666666 7 8 8888 9999 555 444</div>
    <div>4 8 15 16 23 42</div>
    <div>asdf foo bar </div>
  </div>
</div>
</div>

Fiddle: https://jsfiddle.net/m2wr9m06/8/

like image 94
stramin Avatar answered Nov 15 '22 07:11

stramin