这是我的代码:
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;有权输入,但没有成功,不知道该怎么做
答案 0 :(得分:2)
也许是这样?
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">