CSS3 鼠标悬停显示另一面

Myth丶恋晨 2022-07-11 12:24 323阅读 0赞

根据CSS3中的3D特性,当鼠标放上去,反转显示另一面,

源码如下:(代码没考虑浏览器兼容性问题,本代码以Chrome谷歌浏览器测试)

  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. .container{
  8. width:200px;
  9. height:200px;
  10. box-shadow: 2px 2px 1px #999;
  11. margin:160px auto;
  12. }
  13. .item{
  14. /* width: 100%;
  15. height: 100%;*/
  16. position:relative;
  17. /*设置3d特效*/
  18. transform-style: preserve-3d;
  19. /*设置过滤效果*/
  20. transition: transform 1s;
  21. }
  22. .item>img{
  23. display: block;
  24. position:absolute;
  25. top:0px;
  26. left:0px;
  27. right:0px;
  28. bottom:0px;
  29. }
  30. .item>div{
  31. position: absolute;
  32. left:0px;
  33. top:0px;
  34. width:200px;
  35. height:200px;
  36. background-color: #963;
  37. transform: rotateY(180deg);
  38. }
  39. .container:hover .item{
  40. transform: rotateY(180deg);
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <div class="container">
  46. <div class="item">
  47. <img src="01.jpg" alt=""/>
  48. <div>这是反面内容</div>
  49. </div>
  50. </div>
  51. </body>
  52. </html>

打开浏览器,显示

20170125202512906

鼠标放上去后,显示

20170125202602738

发表评论

表情:
评论列表 (有 0 条评论,323人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CSS鼠标悬停

    > 在学习中遇到许多好看的样式,虽然只是用HTML+CSS简单的实现,仅作为我的学习笔记和同爱好学习者的分享: 先看效果 ![这里写图片描述][70] HTM