保留PC端hover样式,取消移动端hover样式

问题:
在pc端hover样式是鼠标悬浮显示,不悬浮就消失;
在移动端,hover样式点击后显示,此后如果我们不做处理,那么hover样式就一直存在。

解决方法:
判断设备是否具备hover事件,决定是否显示hover样式:

@media (any-hover: hover) {
  a:hover {
    background: yellow;
  }
}

这样写就只有支持hover的才会显示hover样式。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以给您提供一个简单的登录页面的 HTMLCSS 代码,并且可以适配不同的屏幕大小。以下是代码示例: HTML代码: ``` <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>登录页面</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <h1>欢迎登录</h1> <form> <label for="username"><b>用户名</b></label> <input type="text" placeholder="请输入用户名" name="username" required> <label for="password"><b>密码</b></label> <input type="password" placeholder="请输入密码" name="password" required> <button type="submit">登录</button> <label> <input type="checkbox" checked="checked" name="remember">记住我 </label> </form> </div> </body> </html> ``` CSS代码: ``` * { box-sizing: border-box; } body { margin: 0; font-family: Arial, Helvetica, sans-serif; background-color: #f1f1f1; } .container { padding: 16px; background-color: #fff; } h1 { text-align: center; color: #333; } input[type=text], input[type=password] { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button[type=submit] { background-color: #4CAF50; color: white; padding: 14px 20px; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer; width: 100%; } button[type=submit]:hover { background-color: #45a049; } label { display: block; color: #666; } input[type=checkbox] { margin-top: 16px; } @media screen and (min-width: 768px) { /* PC端样式 */ .container { width: 50%; margin: 50px auto; } } @media screen and (max-width: 767px) { /* 移动端样式 */ .container { width: 90%; margin: 50px auto; } } ``` 该页面使用了一个容器来包含登录表单,使用了一些常见的样式来美化表单元素。在 CSS 代码中,我们使用了媒体查询来适配不同大小的屏幕。在屏幕宽度大于等于 768px 时,应用 PC 端样式;在屏幕宽度小于 768px 时,应用移动端样式。 希望这个登录页面的示例能够帮助到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值