1

I have a really long text and I want this text to stretch to fit my div's width. I found this but I can't change it to appropriate form in my situation http://jsfiddle.net/eGjak/887/ I made a function which puts words into div "mytext". Can anyone help?

Html:

<div id="parentdiv">
  <div id="mytext"></div>
</div>

Css:

#mytext {
  color: white;
  font-size: 25vmin;
  font-variant: small-caps;
  text-shadow: 0 0 20px #000;
}

#parentdiv {
  display: flex;
  position: absolute;
  top: -4%;
  left: 0%;
  justify-content: center;
  line-height: 1;
}
P.S.
  • 15,970
  • 14
  • 62
  • 86
  • changing this js code to my situation – unknown2549 Dec 16 '16 at 14:41
  • 1
    I don't see any problems in your code. And I don't see how the code did not meet your purpose –  Dec 16 '16 at 14:42
  • I can't put this script into my code. I'm new in programming. I want my parent div to establish maximal width and my text (which is too long) to fit in it. – unknown2549 Dec 16 '16 at 14:44
  • Why can't you specifiy the text tag to 100%. By doing that it will stretch to whatever the size it's being contained within? –  Dec 16 '16 at 14:45
  • So I added to parent div "width: 50%" and to #mytext "width: 100%" but my text just breaks and is much longer than 50%. – unknown2549 Dec 16 '16 at 14:52
  • `ctx.fillText(text, 0, 100);` Why don't you just change the number to 400? –  Dec 16 '16 at 14:58

0 Answers0