Remove 3 pixels in iOS/WebKit textarea

前端 未结 7 1447
说谎
说谎 2021-02-06 23:39

I\'m trying to create a textarea that looks exactly like a div.

However, on iOS there\'s 3 pixels coming from somewhere that I can\'t remove.

7条回答
  •  后悔当初
    2021-02-07 00:37

    Here's a quick JavaScript solution (based on stslavik's approach) that saves some code lines and tests for iPad and iPod as well.

    If you use jQuery:

    if(/iPhone|iPad|iPod/i.test(navigator.userAgent)){
      $('textarea').css('text-indent', '-3px');
    }
    

    If you want to use standard JS:

    if(/iPhone|iPad|iPod/i.test(navigator.userAgent)){
      textareas = document.getElementsByTagName('textarea');
      for(i = 0; i < textareas.length; i++){
        textareas[i].style['text-indent'] = '-3px';
      }
    }
    

提交回复
热议问题