扫码关注官方订阅号
新手求大神解答,我想在移动实现按钮点击点击前一个颜色,点击时一个背景色,松开后一个背景色。
小伙看你根骨奇佳,潜力无限,来学PHP伐。
参考:Safari Web Content Guide
<button ontouchstart="">click me for funny</button>
button { background-color: lightgrey; -webkit-tap-highlight-color: rgba(0,0,0,0); } button:hover { background-color: grey; } button:active { background-color: red; }
demo
css伪元素hover
<button class="color"></button>button:hoverbutton:visited
试试
移动端需要添加样式和js
.item { -webkit-tap-highlight-color: rgba(0,0,0,0); // 隐藏系统自带的背景 // add `ontouchstart` attribte on body // to allow :active work (if :active not work) &:active { background: #ECECEC } }
只添加上面的样式,:active 在移动端不一定(已经引入 zepto 的已经包含下面的 js 了)生效,需要下面的js
document.body.addEventListener('touchstart', function() {}, false); // 也可以直接在body上添加 `ontouchstart` 属性,
参考:https://uedsky.com/2016-05/fr...
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
参考:Safari Web Content Guide

demo
css伪元素hover
<button class="color"></button>
button:hover
button:visited
试试
移动端需要添加样式和js
只添加上面的样式,:active 在移动端不一定(已经引入 zepto 的已经包含下面的 js 了)生效,需要下面的js
参考:https://uedsky.com/2016-05/fr...