<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <style type="text/css"> .wrap { width: 500px; height: 500px; margin: 0 auto; border: 1px solid blue; } .con { width: 80%; height: 100px; margin: 40px auto; border: 1px solid black; } /*必须在父级hover,兼容:IE6+*/ .one:hover p { color: red; } /*标签内要加data-title属性,兼容:IE9+*/ .two:hover::before { content: attr(data-title);/*取到data-title属性的值*/ color: green; } .three:hover::after { content: attr(data-title);/*取到data-title属性的值*/ color: blue; } </style> <body> <p> <p class="con one"> <span>鼠标移进来</span> <p>颜色会变哦</p> </p> <p class="con two" data-title="看我七十二变"> <span>鼠标移进来</span> <p>文字会变哦</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p> </p> <p class="con three" data-title="看我七十二变"> <span>鼠标移进来</span> <p>文字会变哦</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p> </p> </p> </body> </html>
以上就是CSS如何实现hover动态效果的示例代码的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号