HTML5 placeholder css padding

后端 未结 14 1747
失恋的感觉
失恋的感觉 2020-12-04 06:49

I\'ve seen this post already and tried everything I could to change the padding for my placeholder but alas, it seems it just doesn\'t want to cooperate.

Anyway, her

相关标签:
14条回答
  • 2020-12-04 07:07

    The placeholder is not affected by line-height and padding is inconsistent on browsers.

    I have found another solution though.

    VERTICAL-ALIGN. This is probably the only time it works but try that instead and cave many lines of CSS code.

    0 讨论(0)
  • 2020-12-04 07:08

    I had similar issue, my problem was with the side padding, and the solution was with, text-indent, I wasn't realize that text indent effect the placeholder side position.

    input{
      text-indent: 10px;
    }
    
    0 讨论(0)
  • 2020-12-04 07:08
    line-height: normal; 
    

    worked for me ;)

    0 讨论(0)
  • 2020-12-04 07:09

    I have tested almost all methods given here in this page for my Angular app. Only I found solution via   that inserts spaces i.e.

    Angular Material

    add   in the placeholder, like

    <input matInput type="text" placeholder="&nbsp;&nbsp;Email">
    

    Non Angular Material

    Add padding to your input field, like below. Click Run Code Snippet to see demo

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
    
    <div class="container m-3 d-flex flex-column align-items-center justify-content-around" style="height:100px;">
    <input type="text" class="pl-0" placeholder="Email with no Padding" style="width:240px;">
    <input type="text" class="pl-3" placeholder="Email with 1 rem padding" style="width:240px;">
    </div>

    0 讨论(0)
  • 2020-12-04 07:10

    I found the answer that remedied my frustrations regarding this on John Catterfeld's blog.

    ... Chrome (v20-30) implements almost all styles but with a major caveat – the placeholder styles do no resize the input box, so stay clear of things like line-height and padding top or bottom.

    If you are using line-height or padding you are going to be frustrated with the resulting placeholder. I haven't found a way around that up to this point.

    0 讨论(0)
  • 2020-12-04 07:14

    Removing the line-height indeed makes your text align with your placeholder-text, but it doesn't properly solve your problem since you need to adapt your design to this flaw (it's not a bug). Adding vertical-align won't do the deal either. I haven't tried in all browsers, but it doesn't work in Safari 5.1.4 for sure.

    I have heard of a jQuery fix for this, that is not cross-browser placeholder support (jQuery.placeholder), but for styling placeholders, but I haven't found it yet.

    In the meantime, you can resolve to the table on this page which shows different browser support for different styles.

    Edit: Found the plugin! jquery.placeholder.min.js provides you with both full styling capabilities and cross-browser support into the bargain.

    0 讨论(0)
提交回复
热议问题