小程序input框letter-spacing失效,处理方法

拿到这样的图这里写图片描述本来想用letter-spacing方式处理加定位完美设计图,结果在小程序里letter-spacing只对占位符有效。
尝试word-spacing也是没有效果的。于是借鉴他人思路完美解决此问题。

  • block类名为每一个灰色块儿
  • block>view是模拟光标
  • block>text每个块对应的值
  • numList是input框输入的字符串

结构说明每个灰色方块根据输入的value值得长度,控制光标在哪里展示,对应方块的值是多少
input框设置focus=‘true’ auto-focus='true’属性在真机拉起键盘

    <view class='blocks'>
      <view class="block">
        <view wx:if="{{!numList.length}}" class="cursor"></view>
        <text wx:if="{{numList.length}}">{{numList[0]}}</text>
      </view>
      <view class="block">
        <view wx:if="{{numList.length===1}}" class="cursor"></view>
        <text wx:if="{{numList.length>=2}}">{{numList[1]}}</text>
      </view>
      <view class="block">
        <view wx:if="{{numList.length===2}}" class="cursor"></view>
        <text wx:if="{{numList.length>=3}}">{{numList[2]}}</text>
      </view>
      <view class="block">
        <view wx:if="{{numList.length===3}}" class="cursor"></view>
        <text wx:if="{{numList.length>=4}}">{{numList[3]}}</text>
      </view>
      <view class="block">
        <view wx:if="{{numList.length===4}}" class="cursor"></view>
        <text wx:if="{{numList.length>=5}}">{{numList[4]}}</text>
      </view>
      <view class="block">
        <view wx:if="{{numList.length===5}}" class="cursor"></view>
        <text wx:if="{{numList.length>=6}}">{{numList[5]}}</text>
      </view>
       <input type='number' maxlength='6' focus='true' auto-focus='true'></input>

input {//脱离可视区域,偏移太少,输入6位数,可能有会出现input框,偏移太多微信开发者工具没办法输入内容
  margin-left: -120%;
}

.blocks {
  display: flex;
}

.block {
  width: 100rpx;
  height: 88rpx;
  background: #fafafa;
  margin-left: 18rpx;
}

.cursor {//光标的样式
  width: 1px;
  height: 40rpx;
  background-color: #000;
  animation: focus 0.7s infinite;
}

/* 光标动画 */

@keyframes focus {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值