IE浏览器中a:hover设置background失效的解决方法

本文解决了一个在Internet Explorer浏览器中遇到的问题:当使用CSS的a:hover选择器设置背景样式时,IE浏览器不显示背景。通过在链接中添加span标签并调整CSS样式,成功解决了此兼容性问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

hover伪类在IE中有bug以前貌似在网上看到过,但是实际应用中没碰到过,今天正好有个页面需要做一个导航栏,结果a:hover设置background后在IE下是无法显示背景的。

html:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
< ul  id="nav">
     < LI >
             Home
         </ A >
     </ LI >
     < LI >
             Submissions
         </ A >
         < UL >
                     < LI >
                         < A  href="http://preprod-world-2007/knowledge/udc2011/en/Pages/submit.aspx">
                             < span >
                                 Selection process
                             </ span >
                         </ A >
                     </ LI >
         </ UL >
         </ LI >
</ ul >

chrome下显示效果:

css:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#nav, #nav ul{
margin : 0 ;
padding : 0 ;
list-style-type : none ;
list-style-position : outside ;
position : relative ;
line-height : 1.5em ;
background : #b5bd00 ;
}
 
#nav a{
display : block ;
padding : 0px  5px ;
COLOR:  #484848 ; FONT-SIZE:  10px ; FONT-WEIGHT:  bold ;
text-decoration : none ;
}
 
#nav li{
float : left ;
position : relative ;
}
 
#nav ul {
position : absolute ;
display : none ;
width : auto ;
top : 1.5em ;
z-index : 1000 ;
}
 
#nav li ul a{
width : 12em ;
height : auto ;
margin : 2px ;
float : left ;
display : block ;
}
 
#nav li ul li a:hover{
     background : #fff ;
     margin : 2px ;
     display : block ;
}
 
/*#nav li ul li a:hover span{background:#fff; display:block; width:12em;}
*/
#nav ul ul{
top : auto ;
}
 
#nav li ul ul {
left : 12em ;
margin : 0px  0  0  10px ;
}
 
#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li:hover ul ul ul ul{
     
display : none ;
}
#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li li li li:hover ul{
display : block ;
}

  

尽管你怎么样子设置a tag的css都是不管用的,参考了http://www.planabc.net/2007/02/15/ie_hover_bug/

在a tag中增加一个span tag,同时在css中增加

html:

1
2
                                                     of your event</ span ></ A >

css:

1
#nav li ul li a:hover span{ background : #fff display : block width : 16em ;}

  

ok,that's done!


转自:http://www.cnblogs.com/Fred_Xu/archive/2011/09/08/ie-a-hover-background-bug.html

<template> <div class="login-container"> <div class="login-box"> <div class="logo">云盘系统</div> <h2>欢迎回来</h2> <p class="sub-title">请登录您的账户</p> <el-form :model="loginForm" :rules="loginRules" label-width="0" ref="loginFormRef" > <!-- 邮箱 --> <el-form-item prop="email"> <el-input v-model="loginForm.email" placeholder="邮箱" prefix-icon="el-icon-message" /> </el-form-item> <!-- 密码 --> <el-form-item prop="password"> <el-input v-model="loginForm.password" type="password" placeholder="密码" prefix-icon="el-icon-lock" @keyup.enter.native="handleLogin" /> </el-form-item> <!-- 记住密码 --> <el-form-item> <el-checkbox v-model="loginForm.remember">记住密码</el-checkbox> </el-form-item> <!-- 登录按钮 --> <el-form-item> <el-button type="primary" class="login-btn" @click="handleLogin" :loading="loginLoading" > 登录 </el-button> </el-form-item> </el-form> <!-- 快捷登录 --> <div class="social-login"> <div class="divider"> <span>其他登录方式</span> </div> <div class="social-buttons"> <el-button type="link" icon="el-icon-qq" class="social-btn" @click="handleQQLogin"> QQ登录 </el-button> <el-button type="link" icon="el-icon-wechat" class="social-btn" @click="handleWechatLogin"> 微信登录 </el-button> </div> </div> <!-- 注册链接 --> <div class="extra-links"> <router-link to="/register">还没有账号? 立即注册</router-link> <span class="forgot-password" @click="handleForgotPassword">忘记密码?</span> </div> </div> </div> </template> <script setup lang="ts"> import { reactive, ref, onMounted } from 'vue'; import { useRouter } from 'vue-router'; import { ElMessage } from 'element-plus'; const router = useRouter(); const loginFormRef = ref(); const loginLoading = ref(false); const loginForm = reactive({ email: '', password: '', remember: false }); const loginRules = reactive({ email: [ { required: true, message: '请输入邮箱', trigger: 'blur' }, { pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/, message: '请输入正确的邮箱格式', trigger: 'blur' } ], password: [ { required: true, message: '请输入密码', trigger: 'blur' }, { min: 6, max: 15, message: '密码长度应为6-15位', trigger: 'blur' } ] }); // 处理登录 const handleLogin = async () => { (loginFormRef.value as any).validate(async valid => { if (!valid) return; loginLoading.value = true; // 模拟登录请求 await new Promise(resolve => setTimeout(resolve, 1500)); // 实际项目中应调用API验证用户 ElMessage.success('登录成功,即将进入系统'); setTimeout(() => { router.push('/dashboard'); }, 1500); loginLoading.value = false; }); }; // 处理第三方登录 const handleQQLogin = () => { ElMessage.info('QQ登录功能开发中...'); }; const handleWechatLogin = () => { ElMessage.info('微信登录功能开发中...'); }; // 处理忘记密码 const handleForgotPassword = () => { ElMessage.info('密码找回功能开发中...'); }; // 页面加载时检查是否有记住的密码 onMounted(() => { const savedEmail = localStorage.getItem('savedEmail'); const savedPassword = localStorage.getItem('savedPassword'); if (savedEmail && savedPassword) { loginForm.email = savedEmail; loginForm.password = savedPassword; loginForm.remember = true; } }); </script> <style scoped> /* 确保根元素占满屏幕 */ html, body { width: 100%; height: 100%; margin: 0; padding: 0; overflow: auto; } .login-container { min-width: 100vw; min-height: 100vh; background: linear-gradient(135deg, #e6f0ff, #f0f2ff); display: flex; justify-content: center; align-items: center; box-sizing: border-box; padding: 20px; } .login-box { width: 100%; max-width: 400px; background: #fff; border-radius: 12px; padding: 40px 30px; box-shadow: 0 8px 24px rgba(0, 0, 255, 0.1); text-align: center; } .logo { width: 60px; height: 60px; background: #6b6df4; border-radius: 50%; color: #fff; line-height: 60px; font-size: 24px; margin: 0 auto 20px; } h2 { font-size: 24px; color: #333; margin-bottom: 8px; } .sub-title { font-size: 14px; color: #999; margin-bottom: 30px; } .el-input { --el-input-bg-color: #f8f9fe; --el-input-border-color: transparent; --el-input-hover-border-color: transparent; --el-input-focus-border-color: transparent; margin-bottom: 20px; } .login-btn { width: 100%; background: linear-gradient(90deg, #6b6df4, #8490ff); border: none; color: #fff; padding: 12px 0; border-radius: 8px; cursor: pointer; } .login-btn:hover { opacity: 0.9; } .social-login { margin-top: 30px; } .divider { display: flex; align-items: center; margin-bottom: 20px; } .divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: #eee; } .divider span { color: #999; font-size: 14px; padding: 0 15px; } .social-buttons { display: flex; justify-content: center; } .social-btn { color: #6b6df4; font-size: 20px; margin: 0 10px; } .extra-links { display: flex; justify-content: space-between; margin-top: 20px; font-size: 14px; } .extra-links a { color: #6b6df4; text-decoration: none; } .extra-links a:hover, .forgot-password:hover { text-decoration: underline; cursor: pointer; } .forgot-password { color: #6b6df4; } </style> 这个登录的vue组件为什么能占满整个页面
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值