【问题标题】:safari 5.1.7 can't align input placeholder text centersafari 5.1.7 无法对齐输入占位符文本中心
【发布时间】:2015-07-09 14:42:30
【问题描述】:

这是我的代码:

html:

<input type="text" name="Surname" placeholder="Surname" id="surname">

css

::i-block-chroms, input[placeholder]::-webkit-input-placeholder { 
      text-align:center;
}
::-webkit-input-placeholder { 
      text-align:center;
}
input::-webkit-input-placeholder { 
      text-align:center;
}

你怎么看我用不同的方式写了对齐占位符文本中心,我也给了 text-align:center;输入正确,但是没有成功,不知道怎么办

【问题讨论】:

    标签: jquery html css safari


    【解决方案1】:

    也许吧?

    jQuery(function () {
    
        $('[placeholder]').focus(function () {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                if (this.originalType) {
                    this.type = this.originalType;
                    delete this.originalType;
                }
                input.val('');
                input.removeClass('placeholder');
            }
        }).blur(function () {
            var input = $(this);
            if (input.val() == '') {
                if (this.type == 'text') {
                    this.originalType = this.type;
                    this.type = 'text';
                }
                input.addClass('placeholder');
                input.val(input.attr('placeholder'));
            }
        }).blur();
        
    });
    *{
        padding: 0;
        margin: 0;
    }
    body{
        margin: 30px;
    }
    input {
    	box-sizing: border-box;
    	width: 100%;
    	padding: 1em;	
    	text-align: center;
    }
    
    ::i-block-chroms, 
    input[placeholder]::-webkit-input-placeholder { 
          text-align:center;
    }
    ::-webkit-input-placeholder { 
          text-align:center;
    }
    input::-webkit-input-placeholder { 
          text-align:center;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <input type="text" name="Surname" placeholder="Surname" id="surname">

    【讨论】:

    • 非常感谢@Dmitriy,你帮了我很多。
    • 再次嗨@Dmitriy,当您为输入val 提供占位符值时,我遇到了一些问题,有没有办法将占位符文本居中而不将其作为输入值?
    猜你喜欢
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    相关资源
    最近更新 更多