CSS八种hover效果,快用起来_哔哩哔哩_bilibili
以下由于引入了transition所以还需要加兼容性处理:
-ms- :/* IE 9 */
-webkit- :/* Safari 和 Chrome */
-moz- :/* Firefox */
-o- :/* Opera */
-
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .btn1{
- width: 100px;
- height: 40px;
- color: #fff;
- font-size: 20px;
- position: relative;
- background-color: skyblue;
- border: skyblue;
- border-radius: 5px;
- text-align: right;
- padding-right: 20px;
- }
- .btn1:hover img{
- animation: fly 2s ease 1;
- }
- @keyframes fly {
- 0%{
- transform: translateX(0);
- }
- 50%{
- transform: translateX(100px);
- }
- 100%{
- transform: translateX(0);
- }
- }
- .btn1 img{
- width: 20px;
- position: absolute;
- top: 10px;
- left: 10px;
- }
-
- .btn2{
- width: 100px;
- height: 40px;
- color: skyblue;
- font-size: 20px;
- background-color: transparent;
- border-color: skyblue;
- border-radius: 5px;
- }
- .btn2:hover{
- background-color: skyblue;
- color: #fff;
- border: skyblue;
- box-shadow: 0 0 99px 20px skyblue;
- }
-
- .btn3{
- font-size: 20px;
- color:blue;
- background: transparent;
- border: 0;
- text-transform: uppercase;
- padding: 10px 20px;
- box-sizing: border-box;
- position: relative;
- }
- .btn3::before,.btn3::after{
- content:"";
- box-sizing:inherit;
- border: 2px solid transparent;
- width: 0%;
- height: 0%;
- position: absolute;
- }
- .btn3::before{
- top: 0;
- left: 0;
- }
- .btn3::after{
- right: 0;
- bottom: 0;
- }
- .btn3:hover::before{
- border-top-color:blue;
- border-right-color:blue;
- transition: width 0.3s ease-out,height 0.3s ease-out 0.3s;
- width: 100%;
- height: 100%;
- }
- .btn3:hover::after{
- border-bottom-color:blue;
- border-left-color: blue;
- transition: width 0.3s ease-out 0.6s,height 0.3s ease-out 0.9s;
- width: 100%;
- height: 100%;
- }
-
- #btn4{
- width: 150px;
- height: 50px;
- background-color: #0597eb;
- color: #fff;
- font-size: 24px;
- text-align: center;
- line-height: 50px;
- border-radius: 25px;
- overflow: hidden;
- position: relative;
- }
- #btn4 .sp{
- position: absolute;
- z-index: 9;
- color: red;
- }
- #btn4::before{
- position: absolute;
- top: 0;
- left: 0;
- content: "";
- z-index: 0;
- width: 0px;
- height: 100%;
- transition: all 2s ease;
- -webkit-transition:all 2s ease;
- background-color: #aa00aa;
- }
- #btn4:hover::before{
- width: 200px;
- height: 50px;
- }
- #arrow{
- position: absolute;
- background-color: #aa00aa;
- width: 50px;
- height: 50px;
- border-radius: 25px;
- float: left;
- z-index: 9;
- }
- #arrow span{
- float: left;
- color: #fff;
- }
-
- .btn-container{
- position: relative;
- }
- .btn5{
- border: 0;
- border-radius: 50px;
- color: #fff;
- background-color: #5f55af;
- padding: 15px 20px 15px 60px;
- text-transform: uppercase;
- background: linear-gradient(to right,#f72585 50%,#5f55af 50%);
- background-size: 200% 100%;
- background-position: right bottom;
- /* 如果加在 :hover后面,鼠标移出会没有效果 */
- transition: all 2s ease;
- }
- .btn-container span{
- background-color: #f72585;
- height: 100%;
- width: 46px;
- position: absolute;
- left: 0;
- top: 0;
- border-radius: 50%;
-
- }
- button:hover{
- background-position: left bottom;
- }
-
- .btn6{
- color: #fff;
- border: 0;
- background-color: #18a6b8;
- width: 200px;
- height: 50px;
- font-size: 24px;
- border-radius:10px;
- transition: all 2s ease;
- }
- .btn6:hover{
- border-top-left-radius: 50px;
- border-bottom-right-radius: 50px;
- }
-
- .btn7{
- width: 200px;
- height: 50px;
- background: linear-gradient(to right ,#25aae1,#40e495);
- border: 0;
- font-size: 24px;
- color: #fff;
- position: relative;
- border-radius: 50px;
- overflow: hidden;
- }
- .btn7::before{
- content: "";
- width: 0px;
- height: 100%;
- position: absolute;
- top: 0;
- left: 0;
- background-color: rgba(255,255,255,0.5);
- transition:all 2s ease;
- }
- .btn7:hover::before{
- width: 200px;
- }
-
- .btn8{
- padding: 0;
- width: 200px;
- height: 50px;;
- border: 2px solid #fff;
- font-size: 24px;
- color: #fff;
- background-color: #1B2543;
- transition: all 1s ease;
- position: relative;
- box-sizing: content-box;
- overflow: hidden;
- }
- .btn8::before{
- content:'';
- width: 20px;
- height: 50px;
- background-color: rgba(255, 255, 255, 0.1);
- transform: skewX(45deg);
- transform-origin:0%,0%;
- position: absolute;
- top: 0px;
- left: -45px;
- }
- .btn8:hover::before{
- left: 225px;
- transition: all 0.5s linear;
- }
-
- .btn9{
- width: 200px;
- height: 50px;
- border: 0;
- font-size: 24px;
- color: #000;
- font-weight: 600;
- background:linear-gradient(to right ,#FF765D 50%,#fff 50%);
- background-size: 200% 100%;
- background-position: right bottom;
- transition: all 1s ease;
- }
- .btn9:hover{
- background-position: left bottom;
- }
-
- </style>
- </head>
- <body>
- <div id="d1">
- <button class="btn1"><img src="flay.webp" alt="纸飞机"> 按钮1 </button>
- <button class="btn2">按钮2</button>
- <button class="btn3">Hover Me</button>
- <div id="btn4"><div id="arrow"><span>-></span></div><span class="sp">Hover Me</span></div>
- <div class="btn-container"><span>-></span><button class="btn5">Hover Me</button></div></button>
- <button class="btn6">Hover Me</button>
- <button class="btn7">Hover Me</button>
- <button class="btn8">Hover Me</button>
- <button class="btn9">Hover Me</button>
-
- </div>
- </body>
- </html>