css实现鼠标悬停效果

浅浅的花香味﹌ 2021-07-27 01:57 676阅读 0赞

在这里插入图片描述
感觉css的话,原来的我认为很难学,挺生涩的,但是认真看了以后,感觉css很有意思,能写出很多好看的样式,只要多做几个例子,其中有哪个属性不明白,自己查明白,然后把做出来的东西从头到尾顺一遍,思路就会清晰一些,css基础的东西挺简单,就看你会不会利用回了。

html代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <link rel="stylesheet" href="css/鼠标悬停.css">
  8. </head>
  9. <body>
  10. <div class="main">
  11. <div class="item">
  12. <div class="info">
  13. <h3>use what you have</h3>
  14. <p>by Angela Duncan <a href="#">view on more</a></p>
  15. </div>
  16. </div>
  17. <div class="item">
  18. <div class="info">
  19. <h3>use what you have</h3>
  20. <p>by Angela Duncan <a href="#">view on more</a></p>
  21. </div>
  22. </div>
  23. <div class="item">
  24. <div class="info">
  25. <h3>use what you have</h3>
  26. <p>by Angela Duncan <a href="#">view on more</a></p>
  27. </div>
  28. </div>
  29. </div>
  30. </body>
  31. </html>

css代码:

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. a{
  7. text-decoration: none;
  8. }
  9. body,html{
  10. width: 100%;
  11. height: 100%;
  12. }
  13. /* body{ background: #f9f9f9 url(../images/bd.jpg); } */
  14. .main{
  15. width: 100%;
  16. height: 100%;
  17. display: flex;
  18. justify-content: center;
  19. align-items: center;
  20. }
  21. .item{
  22. position: relative;
  23. width: 220px;
  24. height: 220px;
  25. margin: 10px;
  26. background: url(../images/4.jpg) no-repeat;
  27. border-radius: 50%;
  28. box-shadow: inset 0 0 0 16px rgba(255,255,255,.6),0 1px 2px rgba(0,0,0,.1);
  29. transition: all .4s ease-in-out;
  30. }
  31. .item:nth-child(2){
  32. background: url(../images/2.jpg) no-repeat;
  33. }
  34. .item:nth-child(3){
  35. background: url(../images/3.jpg) no-repeat;
  36. }
  37. .info{
  38. opacity: 0;
  39. transform: scale(0);
  40. position: absolute;
  41. width: 100%;
  42. height: 100%;
  43. background: rgba(63, 147, 147,.8);
  44. border-radius: 50%;
  45. text-align: center;
  46. transition: all .4s ease-in-out;
  47. }
  48. .info h3{
  49. height: 140px;
  50. font-size: 22px;
  51. color: #fff;
  52. margin: 0 30px;
  53. padding-top: 45px;
  54. text-transform: uppercase;
  55. letter-spacing: 2px;
  56. }
  57. .info p{
  58. opacity: 0;
  59. font-size: 12px;
  60. color: #fff;
  61. /* 文字倾斜 */
  62. font-style: italic;
  63. margin: 0 30px;
  64. padding-top: 10px;
  65. border-top: 1px solid rgba(255,255,255,.5);
  66. transition: all .4s ease-in-out .4s;
  67. }
  68. .info a{
  69. display: block;
  70. color:#fff ;
  71. font-style: normal;
  72. }
  73. .item:hover{
  74. box-shadow: inset 0 0 0 1px rgba(255,255,255,.1),0 1px 2px rgba(0,0,0,.1);
  75. }
  76. .item:hover .info{
  77. opacity: 1;
  78. transform: scale(1);
  79. }
  80. .item .info p{
  81. opacity: 1;
  82. }
  83. .info p a:hover{
  84. color: #fff222;
  85. }

发表评论

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

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

相关阅读

    相关 CSS鼠标悬停

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