


Use css pseudo-classes to achieve mouse-over button animation effects
The
button is a very common function for developers. The front end usually adds some operation interaction styles to buttons to increase some user experience.
For example: hover style, click style, loading style, etc. Let's learn about css3 animation and css pseudo-classes through simple examples.
Example 1
<button class="btn-1">按钮一</button> <style> button{ position: relative; width: 100px; height: 40px; border: 1px solid #46b0ff; background: none; cursor: pointer; } button:after{ position: absolute; content: ''; width: 100%; height: 100%; top: 0; left: 0; } .btn-1:after{ opacity: 0; background: #46b0ff; transition: all .3s; z-index: -1; } .btn-1:hover:after{ opacity: 1; } </style>
Analysis:
1. Use pseudo-class as mouse: after hover event, For the background of the button, relative positioning (relative) and absolute positioning (absolute) are used here
Remember: when using absolutely positioned elements, the parent element must use relative positioning, otherwise the element will keep looking upwards for the relatively positioned element. , until the root node.
2. Here, transition is used to describe the :hover event animation. The animation is completed in 0.3s and the transparency of :after is changed. all is all behavior.
Of course, we have a simpler implementation here. It is ok to directly change the background without using a type. Please see the code:
<button class="btn-1">按钮一</button> <style> button{ position: relative; width: 100px; height: 40px; border: 1px solid #46b0ff; background: none; cursor: pointer; background: rgba(70, 176, 255, 0); transition: all 1s; } .btn-1:hover{ background: rgba(70, 176, 255, 1); } </style>
ok. Based on Example 1, we will add Further, please see Example 2
Example 2
<button class="btn-2">按钮二</button> <style> ... /* 这里省略上方的公共样式 */ .btn-2:after{ width: 0; background: #f13f84; transition: all .3s; z-index: -1; } .btn-2:hover:after{ width: 100%; } </style>
<button class="btn-3">按钮三</button> <style> ... /* 这里省略上方的公共样式 */ .btn-2:after{ width: 0; background: #f13f84; transition: all .3s; z-index: -1; } .btn-2:hover:after{ width: 100%; } </style>
Introduction to Programming! !
The above is the detailed content of Use css pseudo-classes to achieve mouse-over button animation effects. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
