principle Set a shadow on the element when hovering: box-shadow to make its style different from normal. For box-shadow expressions, see MDN: /* x offset | y offset | shadow color */ box-shadow: 60px -16px teal; /* x offset | y offset | shadow blur radius | shadow color */ box-shadow: 10px 5px 5px black; /* x offset | y offset | shadow blur radius | shadow spread radius | shadow color */ box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, 0.2); /* Insert (shadow inward) | x offset | y offset | shadow color */ box-shadow: inset 5em 1em gold; /* Any number of shadows, separated by commas*/ box-shadow: 3px 3px red, -1em 0 0.4em olive; To specify a single box-shadow:
If only two values are given, they will be interpreted by the browser as an offset on the x-axis and an offset on the y-axis.
The following are several styles that are used many times in this blog system. 1. Mouse hover to imitate the folded paper style Code implementation: The <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Mouse hover simulates the style of folded paper</title> </head> <style type="text/css"> /* Core styles */ .card { width: 300px; height: 180px; border: 10px solid #FFF; border-bottom: 0 none; background-color: #FFF; box-shadow: 0 1px 1px 0 rgba(0, 0, 0, .15) } .card:hover { box-shadow: 0 5px 5px 0 rgba(0, 0, 0, .25); transition: all .2s ease-in-out; } /* Non-core styles */ .card-header { text-align: center; } .card-body, .card-footer { text-align: left; } </style> <body style="background: #e3e3e3;"> <div class="card"> <div class="card-header"> <p>This is a card</p> </div> <div class="card-body"> <p>Description: When the mouse is hovering, the effect is similar to the folding of paper</p> </div> <div class="card-footer"> <p>Principle: Change the offset on the y-axis and the shadow diffusion radius (the second and third numbers)</p> </div> </div> </body> </html> 2. Mouse hover imitating paper focus style Code implementation: The difference from the above is that the specific values of <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Mouse hover simulates paper focus style</title> </head> <style type="text/css"> /* Core styles */ .card { padding: 10px; width: 300px; height: 180px; background-color: #FFF; box-shadow: none; } .card:hover { box-shadow: 0 1px 6px 0 rgba(0, 0, 0, .2); border-color: #eee; transition: all .2s ease-in-out; } /* Non-core styles */ .card-header { text-align: center; } .card-body, .card-footer { text-align: left; } </style> <body style="background: #e3e3e3;"> <div class="card"> <div class="card-header"> <p>This is a card</p> </div> <div class="card-body"> <p>Description: When the mouse is hovering, the whole paper is in focus</p> </div> <div class="card-footer"> <p>Principle: Change the offset on the y-axis and the shadow diffusion radius (the second and third numbers)</p> </div> </div> </body> </html> 3. Mouse hover imitates paper lifting style Code implementation: By combining <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Mouse hover simulates the style of paper lifting</title> </head> <style type="text/css"> /* Core styles */ .card { padding: 10px; width: 300px; height: 180px; background-color: #FFF; border: none; border-radius: 6px; -webkit-transition: all 250ms cubic-bezier(0.02, 0.01, 0.47, 1); transition: all 250ms cubic-bezier(.02, .01, .47, 1); } .card:hover { box-shadow: 0 16px 32px 0 rgba(48, 55, 66, 0.15); transform: translate(0,-5px); transition-delay: 0s !important; } .box-shadow { -webkit-box-shadow: 0 0.25rem 1rem rgba(48, 55, 66, 0.15); box-shadow: 0 4px 16px rgba(48, 55, 66, 0.15); } /* Non-core styles */ .card-header { text-align: center; } .card-body, .card-footer { text-align: left; } </style> <body style="background: #e3e3e3;"> <div class="card box-shadow"> <div class="card-header"> <p>This is a card</p> </div> <div class="card-body"> <p>Description: When the mouse is hovered, the whole paper is lifted</p> </div> <div class="card-footer"> <p>Principle: Add transform attribute</p> </div> </div> </body> </html> 4. Mouse hover imitates paper rising style (animation implementation) Code implementation: Use the <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>When the mouse hovers, it simulates the style of paper rising</title> </head> <style type="text/css"> /* Core styles */ .card { padding: 10px; width: 300px; height: 180px; background-color: #FFF; border: none; border-radius: 6px; -webkit-transition: all 250ms cubic-bezier(0.02, 0.01, 0.47, 1); transition: all 250ms cubic-bezier(.02, .01, .47, 1); } .card:hover { animation: fly 0.0001s linear; animation-fill-mode: both; } @keyframes fly { 0% { box-shadow: 2px 2px 2px #e2dede, -2px 2px 2px #e2dede; } 100% { box-shadow: 6px 8px 12px #e2dede, -6px 8px 12px #e2dede; } } /* Non-core styles */ .card-header { text-align: center; } .card-body, .card-footer { text-align: left; } </style> <body style="background: #e3e3e3;"> <div class="card box-shadow"> <div class="card-header"> <p>This is a card</p> </div> <div class="card-body"> <p>Description: When the mouse hovers, the whole paper rises</p> </div> <div class="card-footer"> <p>How it works: Using the @keyframes rule to create animations</p> </div> </div> </body> </html> The above is the details of the example of how to use CSS to achieve the floating effect of cards when the mouse hovers over them. For more information about how to use CSS to achieve the floating effect of cards when the mouse hovers over them, please pay attention to other related articles on 123WORDPRESS.COM! |
<<: In-depth understanding of the life cycle comparison between Vue2 and Vue3
>>: Common shell script commands and related knowledge under Linux
Table of contents DOMContentLoaded and load What ...
The pitfalls 1. Many tutorials on the Internet wr...
Win2008 R2 zip format mysql installation and conf...
MJML is a modern email tool that enables develope...
I started using Linux for development and enterta...
This article uses an example to describe how MySQ...
Table of contents What is two-way data binding Im...
HTML meta viewport attribute description What is ...
1. Abnormal performance of Docker startup: 1. The...
1. To optimize the query, try to avoid full table...
Template 1: login.vue <template> <p clas...
Nginx is used as the server, Mongo is used as the...
Table of contents 1. Original value and reference...
Table of contents 1. Prepare materials 2. Downloa...
This article example shares the specific code of ...