Loading Please Wait...

Logo Lynxsia IT Solutions

CSS Transitions

CSS Transitions

CSS transitions allows you to change property values smoothly, over a given duration.

CSS transitions provide a way to control animation speed when changing CSS properties, like during mouse hover, click, etc.

Defining The Transitions

To define the transition, we have following properties:

transition-property: specifies the name or names of the CSS properties to which transitions should be applied such as width, height, font-size, all, etc. The value all can be used to select all properties to which transition can be applied.

transition-duration: specifies the duration over which transitions should occur.

transition-delay: Defines how long to wait between the time a property is changed and the transition actually begins.

transition-timing-function: specifies a function to define how intermediate values for properties are computed.

The transition-timing-function property can have the following values:

  • ease: specifies a transition effect with a slow start, then fast, then end slowly
  • linear: specifies a transition effect with the same speed from start to end
  • ease-in: specifies a transition effect with a slow start
  • ease-out: specifies a transition effect with a slow end
  • ease-in-out: specifies a transition effect with a slow start and end
  • cubic-bezier(x1,y1,x2,y2): lets you define your own values in a cubic-bezier function
					 
        
          <!DOCTYPE html>
          <html>
            <head>
              <style>
                div {
                  width: 100px;
                  height: 100px;
                  background-color: #1a1e49;
                  transition-property: width;
                  transition-duration: 2s;
                  transition-delay: 1s;
                  transition-timing-function: linear;
                }

                div:hover {
                  width: 200px;
                }
              </style>
            </head>
            <body>
              <div></div>
            </body>
          </html>
        
      
Transition Shorthand

The CSS transition is a shorthand property to handle all transition sub properties in a single line.

Syntax
					 
        
          transition: property duration timing-function delay;
        
      
					 
        
          <!DOCTYPE html>
          <html>
            <head>
              <style>
                div {
                  width: 100px;
                  height: 100px;
                  background-color: #1a1e49;
                  transition: width 3s linear 1s;
                }

                div:hover {
                  width: 200px;
                }
              </style>
            </head>
            <body>
              <div></div>
            </body>
          </html>
        
      
Handling Multiple Properties
					 
        
          <!DOCTYPE html>
          <html>
            <head>
              <style>
                div {
                  width: 100px;
                  height: 100px;
                  background-color: #1a1e49;
                  transform: rotate(0);
                  transition: width 2s, height 2s, transform 2s;
                }

                div:hover {
                  width: 200px;
                  height: 200px;
                  transform: rotate(45deg);
                }
              </style>
            </head>
            <body>
              <div></div>
            </body>
          </html>
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved