div模拟输入框input/textarea

//html
<!--填写信息--> <div class="info-wrap"> <form class="formToCheck" id="formToCheck" method="get" action="#"> <div class="info-box"> <div contenteditable="true" class="link-textarea user-name" data-form-type="name"></div> </div> <div class="info-box"> <div contenteditable="true" class="link-textarea user-moblie" data-form-type="mobile"></div> </div> <div class="adress-box"> <div contenteditable="true" class="link-textarea" data-form-type="address"></div> </div> <div class="reason-box"> <div class="reason-tilte">申请理由</div> <div contenteditable="true" class="link-textarea" data-form-type="reason"></div> </div> </form> </div>

//在IOS中<div contenteditable="true"></div>中点击时可以弹出键盘但是无法输入。加一个样式-webkit-user-select:text就可以了。

.link-textarea:focus {
    border: none;
    outline: none;
    -webkit-appearance: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
    -webkit-text-size-adjust: none;
    color: rgba(0, 0, 0, 0);
	background-color: #fff
}
.user-name:empty:after {
    content: '姓名';
    color: #ababab;
    font-size: 15px;
    text-align: left;
}
.user-moblie:empty:after {
    content: '手机号';
    color: #ababab;
    font-size: 15px;
    text-align: left;
}
.info-box,
.adress-box {
    width: 90.625%;
    margin: 0 auto;
    height: auto;
    min-height: 45px;
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    margin-bottom: 9px;
    box-sizing: border-box;
}
.info-box .link-textarea,
.adress-box .link-textarea {
    margin: 12px 0px 12px 9px;
    font-size: 15px;
    color: #3b3b3b;
    outline: 0;
    word-wrap: break-word;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-user-modify: read-write-plaintext-only;
	-webkit-user-select:text;
}
.adress-box .link-textarea:empty:after {
    content: '详细地址';
    color: #ababab;
    font-size: 15px;
    text-align: left;
}
.reason-box {
    width: 90.625%;
    margin: 0 auto;
    height: auto;
    min-height: 100px;
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    box-sizing: border-box;
}
.reason-box .link-textarea {
    margin: 10px 0px 12px 9px;
    font-size: 15px;
    color: #3b3b3b;
    outline: 0;
    word-wrap: break-word;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-user-modify: read-write-plaintext-only;
	-webkit-user-select:text;//兼容ios上点击可弹出键盘无法输入的问题
}
.reason-box .link-textarea:empty:after {
    content: '以申请理由为基本评判,请认真填写。';
    color: #ababab;
    font-size: 11px;
    text-align: left;
}
.reason-tilte {
    line-height: 15px;
    font-size: 15px;
    color: #ababab;
    margin: 12px 0 0 9px;
}

//为什么会用div来模拟输入框input?

因为,input只能一行显示出输入的文字,如果需要是多行显示出输入的文字就可以用这种方法,

//多行显示出输入的文字,那为什么不直接用textarea呢?

textarea和input都不支持伪类(after,empty,focous等),想要在textarea或者input元素上使用伪类来实现样式是不支持的

转载于:https://www.cnblogs.com/xiaosuibu/p/6742461.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值