placeholder 靠右垂直居中/位置兼容

1.input輸入框文字靠右垂直居中。

2.placehoder提示同樣靠右垂直居中。(?placeholder是HTML5? input的新屬性,英文意思是占位符,它一般表示input輸入框的默認(rèn)提示值。)

css代碼

input {

? ? text-align: right;

? ? font-size:0.3rem;

? ? width:100%;

? ? height:0.78rem;

? ? line-height:0.78rem;

}

瀏覽器渲染各種正常,然后在低版本(比如某三星的4.3)Android webview 渲染的時候,placeholder 跑偏了.....位于左上角,并且只是placeholder,輸入的時候正常居右垂直居中。


純css解決方案

第一步:實(shí)現(xiàn)placehoder垂直居中

css代碼

input {

text-align: right;

font-size:0.3rem;

width:100%;

height:0.78rem;

padding:0.24rem 0;? //用padding實(shí)現(xiàn)居中而不是line-hieght

line-height:0.3rem;

box-sizing: border-box;

}

第二步:使用direction實(shí)現(xiàn)placehoder把文本方向設(shè)置為“從右向左”:

input::-webkit-input-placeholder { /* WebKit browsers */ direction: rtl;}

input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ direction: rtl;}

input::-moz-placeholder { /* Mozilla Firefox 19+ but I'm not sure about working */ direction: rtl;}

input:-ms-input-placeholder { /* Internet Explorer 10+ */ direction: rtl;}


語法

E::placeholder{ sRules }


相關(guān)參考

palacehoder設(shè)置

CSS direction 屬性

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容