Swordwhisper 2023-02-03 12:28 采纳率: 60%
浏览 55
已结题

H5的按钮样式,无法在uniapp中显示

在UIverse上看到一个checkBox很好看 但是是H5写的,导入到uniapp中点击没有响应,原因就是H5的checkBox和uniapp的checkbox是不一样的。

<label class="switch">
  <input type="checkbox">
  <span class="slider"></span>
</label>
/* The switch - the box around the slider */
.switch {
 font-size: 1rem;
 position: relative;
 display: inline-block;
 width: 4em;
 height: 2em;
}

/* Hide default HTML checkbox */
.switch input {
 opacity: 0;
 width: 0;
 height: 0;
}

/* The slider */
.slider {
 position: absolute;
 cursor: pointer;
 inset: 0;
 background-color: #eee;
 transition: 0.4s;
 border-radius: 0.5em;
 box-shadow: 0 0.2em #dfd9d9;
}

.slider:before {
 position: absolute;
 content: "";
 height: 1.5em;
 width: 1.4em;
 border-radius: 0.3em;
 left: 0.3em;
 bottom: 0.7em;
 background-color: lightsalmon;
 transition: 0.4s;
 box-shadow: 0 0.4em #bcb4b4;
}

.slider:hover::before {
 box-shadow: 0 0.2em #bcb4b4;
 bottom: 0.5em;
}

input:checked+.slider:before {
 transform: translateX(2em);
 background: lightgreen;
}

就是这样一个switch按钮
如何才能在uniapp中使用?

  • 写回答

3条回答 默认 最新

  • 成茂峰 2023-02-03 14:05
    关注

    原因是uniapp对input标签做了处理,成了内置组件,type不再支持checkbox,样式还有编译后的dom也发生了变化。

    img

    详情:https://uniapp.dcloud.net.cn/component/input.html#type

    img

    要想要的效果,建议手写一个组件不是input标签,采用view,添加监听事件来实现交互。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月6日
  • 已采纳回答 3月29日
  • 创建了问题 2月3日