Remove 3 pixels in iOS/WebKit textarea

前端 未结 7 1448
说谎
说谎 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:27

    Okay... Sorry... Here we go... The officially unofficial answer is...

    You can't get rid of it.

    Apparently this is a "bug" with mobile safari on inputs. See:

    • padding bug on Safari mobile?
    • iPhone

    You can, however, knowing the indent do this

    textarea {
      text-indent:-3px;
    }
    

    It's not a pretty solution, but it does what you need.

    Edit Forgot to mention, tested with iOS Simulator. You might try on your phone itself.

    Another point: This also assumes that you're serving up css solely for mobile safari, specifically for the iPhone. An older way of doing this is:

    /* Main CSS here */
    
    /* iPhone CSS */
    @media screen and (max-device-width: 480px){
      /* iPhone only CSS here */
      textarea {
        text-indent: -3px;
      }
    }
    

    Edit Again I'm having way too much fun with this... You can also use separate stylesheets with these declarations:

     
     
     
     
    

    Edit Because apparently somebody bought an Android ;)

    
    

    Personally, I don't really have a problem with text-entries having some internal indentation. It clears it from the area's edge and makes it more readable. I do, however, believe that a browser should support the spec. So here's an update for differentiating between android and iPhone. Have fun!

提交回复
热议问题