2

I have a div element. Inside the element I have a CK editor. What I want is that it cant input text when it is greater than some lines.

I tried calculating the offsetheight of the element and I have set height for an element.so i am checking by offsertheight/maxheight*100 which should not be greater than 100%.

const taHeight = divElement.offsetHeight;
currentHeightPercentage = Math.floor((taHeight / maxHeightAllowed) * 100);

So this works fine but the difference comes if I use an iPad then I am able to enter more lines of text but in laptop I am unable to enter the same number of lines as I could enter in iPad.

Anas
  • 971
  • 13
  • 28
  • can you share your html css and ts on Stackbliz or here – HaSnen Tai Nov 11 '19 at 11:09
  • Why don't you count the words instead of lines? – Akash Agrawal Nov 11 '19 at 11:14
  • @AkashAgrawal how do i do that? – taashibhulani Nov 11 '19 at 11:14
  • @taashibhulani, you must be storing the entire text from CK editor in a variable? If yes, then all you have to do is this.yourVar.length. It'll give you the length of text (including spaces). – Akash Agrawal Nov 11 '19 at 11:25
  • @AkashAgrawal ok . no i dont want to do that because there are multiple ck editors and then each have different height. So rather i would prefer to have max number of lines . But my only problem is with the different screen sizes shows different height for the same element. in big screen suppose i get offset height as 380 then in small screen i get it as 360. – taashibhulani Nov 11 '19 at 11:29
  • Can anyone help me on this? – taashibhulani Nov 11 '19 at 12:52
  • @taashibhulani did you check [this question](https://stackoverflow.com/questions/3922739/limit-text-length-to-n-lines-using-css) and [this question](https://stackoverflow.com/questions/49654919/how-to-show-only-three-lines-not-more-than-three-lines-of-a-paragraph-using-cs/49655122#49655122)? – Christian Vincenzo Traina Nov 11 '19 at 13:17
  • @CristianTraìna This also i have tried but it doesnt solve the issue that i have – taashibhulani Nov 11 '19 at 15:01

0 Answers0