Calculating text width

后端 未结 22 1357
轻奢々
轻奢々 2020-11-22 03:36

I\'m trying to calculate text width using jQuery. I\'m not sure what, but I am definitely doing something wrong.

So, here is the code:

var c = $(\'.c         


        
22条回答
  •  醉酒成梦
    2020-11-22 03:39

    after chasing a ghost for two days, trying to figure out why the width of a text was incorrect, i realized it was because of white spaces in the text string that would stop the width calculation.

    so, another tip is to check if the whitespaces are causing problems. use

     
    

    non-breaking space and see if that fixes it up.

    the other functions people suggested work well too, but it was the whitespaces causing trouble.

提交回复
热议问题