開發項目中表單常用的清楚樣式:
1、改變placeholder默認字體顏色
::-webkit-input-placeholder{color: #333;} :-moz-placeholder{color: #333;} :-moz-placeholder{color: #333;} :-ms-input-placeholder{color: #333;}
2、取消input number的上下箭頭
input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{-webkit-appearance: none !important;} input[type="number"]{-moz-appearance:textfield;}
3、select下拉選擇框option文字右對齊
direction: rtl;
4、select右邊箭頭隱藏
-webkit-appearance: none;
5、清除textarea右下角可拖拽功能
resize:none;
6、textarea文本框高度自適應
<div class="ta_box"> <textarea class="ta"></textarea> </div>
.ta_box{ width: 400px; height: auto; overflow: hidden; border: 1px solid #999; box-sizing: border-box; } .ta{ min-height: 30px; outline: none; resize: none; width: 500px; box-sizing: border-box; vertical-align: top; border: none; }
$.fn.autoHeight = function () { function autoHeight (elem) { elem.style.height = 'auto'; elem.scrollTop = 0; //防抖動 elem.style.height = elem.scrollHeight + 'px'; } this.each(function () { autoHeight(this); $(this).on('keyup',function () { autoHeight(this); }); }); } $('textarea').autoHeight();
這里的代碼需要引用JQ,而結構之中最外層的.ta_box是為了消除滑塊,優化用戶體驗.
這里用到了JQ的擴展函數