CSS3 uses the transition property to achieve transition effects

CSS3 uses the transition property to achieve transition effects

Detailed description of properties

The purpose of the transition attribute is to make some CSS properties (such as background) appear with a smooth transition effect. It is a combined attribute that is composed of the following four attributes:

  • transition-property: Sets the CSS property that applies the transition, such as background.
  • transition-duration: Sets the duration of the transition effect. The default is 0.
  • transition-timing-function: Set the timing curve of the transition effect. The default is "ease".
  • transition-delay: Specifies when the transition effect begins. The default is 0.

Example:

 button{
    transition: background 1s;
    -webkit-transition: background 1s; /* Safari */
 }

When defining transition properties, transition-property and transition-duration are required, and the other two are optional.

transition-property and transition-duration

transition-property is used to specify the CSS properties for applying transition effects. These properties include (may not be complete):

  • width
  • height
  • color
  • background (color, image, position)
  • transform (in the next post)
  • border (color, width)
  • position (top, bottom, left, right )
  • text (size, weight, shadow, word-spacing)
  • margin
  • padding
  • opacity
  • visibility
  • z-index
  • all

The transition-duration property is used to set the duration of the transition effect of the specified property, which can be seconds (s) or milliseconds (ms).

transition-delay and transition-timing-function

transition-delay is used to set the time when the transition effect starts. The default value is 0 and can be seconds (s) or milliseconds (ms). If transition-delay is a negative number, it means that the transition effect starts early.

transition-timing-function is used to set the transition effects, which include:

  • ease - slow at the beginning, fast in the middle, and slow at the end
  • ease-in - Slow in and fast out
  • ease-out - Ease-out effect, fast in and slow out.
  • ease-in-out - slow start and slow end
  • cubic-bezier(n,n,n,n) - Define your own values ​​in the cubic-bezier function. Possible values ​​are between 0 and 1.

Example:

 button{
   transition: background 1s ease-in-out 2s;
   -webkit-transition: background 1s ease-in-out 2s; /* Safari */
 }

Multiple attributes

For multiple properties, the effects of each property are separated by commas:

  button{
     transition: background 1s ease-in-out 2s, width 2s linear;
     -webkit-transition: background 1s ease-in-out 2s, width 2s linear; /* Safari */
   }

compatibility

Internet Explorer 10, Firefox, Opera, and Chrome support the transition property.

Safari supports the alternative -webkit-transition property.

Internet Explorer 9 and earlier versions do not support the transition property.

trigger

It should be noted that transition effects require previously defined properties, and transition effects are applied through triggers, such as :hover, :focus, and :active.

Summarize

The above is what I introduced to you about using the transition attribute in CSS3 to achieve transition effects. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Two simple ways to remove text watermarks from web pages

>>:  Detailed explanation of the basic usage of VUE watch listener

Recommend

Semanticization of HTML tags (including H5)

introduce HTML provides the contextual structure ...

5 MySQL GUI tools recommended to help you with database management

There are many database management tools for MySQ...

A simple way to achieve scrolling effect with HTML tag marquee (must read)

The automatic scrolling effect of the page can be...

Web design must also first have a comprehensive image positioning of the website

⑴ Content determines form. First enrich the conten...

Docker beginners' first exploration of common commands practice records

Before officially using Docker, let's first f...

MySQL Installer Community 5.7.16 installation detailed tutorial

This article records the detailed tutorial of MyS...

Don’t bother with JavaScript if you can do it with CSS

Preface Any application that can be written in Ja...

How to block IP and IP range in Nginx

Written in front Nginx is not just a reverse prox...

mysql5.7.17 installation and configuration example on win2008R2 64-bit system

123WORDPRESS.COM has explained to you the install...

js canvas to realize the Gobang game

This article shares the specific code of the canv...

Example of how to create and run multiple MySQL containers in Docker

1. Use the mysql/mysql-server:latest image to qui...

Solution to forgetting the root password of MySQL 5.7 and 8.0 database

Note: To crack the root password in MySQL5.7, you...

Specific use of Linux man command

01. Command Overview Linux provides a rich help m...

Detailed explanation of the basic use of react-navigation6.x routing library

Table of contents react-native project initializa...

Introduction to the use of MySQL official performance testing tool mysqlslap

Table of contents Introduction Instructions Actua...