SlideShare a Scribd company logo
CSS3 Transitions
CSS Transitions Introduction




   CSS Transitions allow property changes in CSS values to occur smoothly over a
   specified duration. This smoothing animates the changing of a CSS value when
   triggered by a mouse click, focus or active state, or any changes to the element
   (including even a change on the element’s class attribute).
Basic Rollover


 HTML:

   <a href="#" class="button">Transition me!</a>



 CSS:

  a.button {
     padding: 5px 10px;
     background: #4EBFBF;
     color: #fff;
     text-decoration: none;
    }

  a.button:hover {
         background: #690;
    }
Basic Rollover with Transition


 HTML:

   <a href="#" class="button">Transition me!</a>


 CSS:
  a.button {
     padding: 5px 10px;
     background: #4EBFBF;
     color: #fff;
     text-decoration: none;
     -moz-transition-property: background;
     -moz-transition-duration: 0.3s;
     -moz-transition-timing-function: ease;
    }

  a.button:hover {
         background: #690;
    }
Basic Rollover with Transition




                    background: #4EBFBF;
                    transition-property: background;
                    transition-duration: 0.3s;
                    transition-timing-function: ease;




    transition-property: The property to be transitioned (in this case, the background property)
    transition-duration: How long the transition should last (0.3 seconds)
    transition-timing-function: How fast the transition happens over time (ease)
Timing Function



                        transition-timing-function: ease;


    The timing function value allows the speed of the transition to change over time by
    defining one of six possibilities: ease, linear, ease-in, ease-out, ease-in-out, and cubic-
    bezier (which allows you to define your own timing curve).
Timing Function




       If you slept through geometry in high school like I did, don’t worry. I recommend
       simply plugging in each of these timing function values to see how they differ.

       …For longer animations, the timing function you choose becomes more of an
       important piece of the puzzle, as there’s time to notice the speed changes over the
       length of the animation.

       When in doubt, ease (which is also the default value) or linear should work just fine for
       short transitions.

       - Dan Cederholm
       http://www.alistapart.com/articles/understanding-css3-transitions
Shorthand Code




                 transition-property: background;
                 transition-duration: 0.3s;
                 transition-timing-function: ease;


                              Is the same as:



                 transition: background 0.3s ease;
Browser Compatibility




  The transition property is not supported in any browsers.
  Firefox 4 supports an alternative, the -moz-transition property.
  Safari and Chrome support an alternative, the -webkit-transition property.
  Opera supports an alternative, the -o-transition property.




                -webkit-transition: background 0.3s ease;
                -moz-transition: background 0.3s ease;
                -o-transition: background 0.3s ease;
                transition: background 0.3s ease;
Browser Compatibility
Wouldn’t it make more sense if the transition properties were placed in the :hover declaration,
since that’s the trigger for the transition?

The answer is that there are other possible states of an element besides :hover, and you’ll likely
want that transition to happen on each of those without duplication.

For instance, you may want the transition to also happen on the :focus or :active pseudo-classes
of the link as well. Instead of having to add the transition property stack to each of those
declarations, the transition instructions are attached to the normal state and therefore declared
only once.

- Dan Cederholm
http://www.alistapart.com/articles/understanding-css3-transitions
Transitioning multiple properties



   Let’s say that along with the background color, we also want to change the link’s text color
   and transition that as well. We can do that by stringing multiple transitions together,
   separated by a comma. Each can have their varying duration and timing functions .


       a.button {
       padding: 5px 10px;
       background: #4EBFBF;
       color: #fff;
       -webkit-transition: background .3s ease, color 0.2s linear;
       -moz-transition: background .3s ease, color 0.2s linear;
       -o-transition: background .3s ease, color 0.2s linear;
       transition: background .3s ease, color 0.2s linear;
       }

       a.button:hover, a.button:focus {
       color: #030; background: #690;
       }


                                                    Text via: http://www.alistapart.com/articles/understanding-css3-transitions
Transitioning multiple properties


   An alternative to listing multiple properties is using the all value. This will transition all
   available properties.

   Let’s drop all into our simple example instead of listing background and color separately.
   They’ll now share the same duration and timing function.

                         a.button {
                         padding: 5px 10px;
                         background: #4EBFBF;
                         color: #fff;
                         -webkit-transition: all 0.3s
                         ease;
                         -moz-transition: all 0.3s ease;
                          -o-transition: all 0.3s ease;
                         transition: all 0.3s ease;
                         }

                         a.button:hover, a.button:focus {
                         color: #030; background: #690;
                         }
                                                       Text via: http://www.alistapart.com/articles/understanding-css3-transitions
Example B:


 div.exampletransitionb {               CSS
     width: 520px;
 }
 div.exampletransitionb div {
     background-color: #ED8029;
     border-radius: 5px 5px 5px 5px;
     color: white;
     margin: 5px 0;
     padding: 5px;
     text-align: right;
     width: 100px;
 }
 div.exampletransitionb:hover div {
     width: 500px;
 }
 div.exampletransitionb div.ease {
     -moz-transition: all 3s ease 0s;          <div class="exampletransitionb">
                                                                                                      HTML
 }
 div.exampletransitionb div.linear {
                                               <div   class="ease">ease</div>
     -moz-transition: all 3s linear 0s;
 }
                                               <div   class="linear">linear</div>
 div.exampletransitionb div.easein {           <div   class="easein">ease-in</div>
     -moz-transition: all 3s ease-in 0s;       <div   class="easeout">ease-out</div>
 }                                             <div   class="easeinout">ease-in-out</div>
 div.exampletransitionb div.easeout {
     -moz-transition: all 3s ease-out 0s;      </div>
 }
 div.exampletransitionb div.easeinout {
     -moz-transition: all 3s ease-in-out 0s;
 }                                                      Example via: http://www.css3.info/preview/css3-transitions/
http://leaverou.github.com/animatable/
http://tympanus.net/Tutorials/BlurMenu/index.html
Further Reading




         www.alistapart.com/articles/understanding-css3-transitions
         http://www.w3schools.com/css3/css3_transitions.asp
         http://www.impressivewebs.com/css3-transitions-without-hover
         http://www.netmagazine.com/tutorials/more-efficient-css3-transitions
         http://en.wikipedia.org/wiki/12_basic_principles_of_animation

More Related Content

PPT
Basics of html5, data_storage, css3
PDF
Introduction to Vim, the text editor
PDF
SQS ingress for AWS Lambda
PDF
What is Vim?
PPT
Shopping items
PDF
Our GBU bioepistemological educational project (BEEMP)
PDF
Presentatie KGI VIDEO TV
PPTX
Vietnam
Basics of html5, data_storage, css3
Introduction to Vim, the text editor
SQS ingress for AWS Lambda
What is Vim?
Shopping items
Our GBU bioepistemological educational project (BEEMP)
Presentatie KGI VIDEO TV
Vietnam

Viewers also liked (20)

PDF
affTA04 - BAB IV
PDF
Capitulo 6
PPSX
African Farmer game walkthrough
PPT
Children’s rights
PPTX
Planning sheets for final piece
PPTX
How to pledge for Kickstarter
PDF
PS - the delivery of public speaking
PDF
Dskp rbt tahun 6
PPTX
Веда Пульс - для специалистов
PDF
Whitby Seafoods - Office Refurbishment Project
PPTX
For (;;)
PPTX
Ukita june 2011pptx
PDF
Outland res. brochure 6 30-11 brown
DOC
Unit 57 terminology becky doyle
PDF
RAJIV GANDHI PR SASHAKTIKARAN YOJANA {RGPSA}
PDF
Anexo 12 pc 66707 alimentação (1)
PPT
Interactive Reader + Foldable
PDF
Mortgage Backed Securities
PDF
Ba759 e70 4b70-45e3-896deb1f6574f53e
PDF
2011 2012 annual report
affTA04 - BAB IV
Capitulo 6
African Farmer game walkthrough
Children’s rights
Planning sheets for final piece
How to pledge for Kickstarter
PS - the delivery of public speaking
Dskp rbt tahun 6
Веда Пульс - для специалистов
Whitby Seafoods - Office Refurbishment Project
For (;;)
Ukita june 2011pptx
Outland res. brochure 6 30-11 brown
Unit 57 terminology becky doyle
RAJIV GANDHI PR SASHAKTIKARAN YOJANA {RGPSA}
Anexo 12 pc 66707 alimentação (1)
Interactive Reader + Foldable
Mortgage Backed Securities
Ba759 e70 4b70-45e3-896deb1f6574f53e
2011 2012 annual report
Ad

Similar to CSS3 Transitions (20)

PDF
HTML5 and CSS3 – exploring mobile possibilities - Dynabyte event
PDF
HTML5 and CSS3 – exploring mobile possibilities - Frontend Conference Zürich
PDF
Css3 transitions and animations + graceful degradation with jQuery
PDF
Workshop 18: CSS Animations & cool effects
PDF
Dynamic CSS: Transforms, Transitions, and Animation Basics
PDF
CSS3 Transforms Transitions and Animations
PPTX
PPT
PDF
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
TXT
Blog skins396734
PPT
PPTX
CSS 3 Overview
DOCX
Angular js animate shashikant bhongale -20-7-16
PPTX
CSS3 TTA (Transform Transition Animation)
PDF
DotNetNuke World CSS3
PDF
Add Some Awesome-Sauce
KEY
CSS and CSS3
KEY
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
PDF
The CSS of Tomorrow (Front Row 2011)
HTML5 and CSS3 – exploring mobile possibilities - Dynabyte event
HTML5 and CSS3 – exploring mobile possibilities - Frontend Conference Zürich
Css3 transitions and animations + graceful degradation with jQuery
Workshop 18: CSS Animations & cool effects
Dynamic CSS: Transforms, Transitions, and Animation Basics
CSS3 Transforms Transitions and Animations
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
Blog skins396734
CSS 3 Overview
Angular js animate shashikant bhongale -20-7-16
CSS3 TTA (Transform Transition Animation)
DotNetNuke World CSS3
Add Some Awesome-Sauce
CSS and CSS3
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
The CSS of Tomorrow (Front Row 2011)
Ad

More from hstryk (16)

PPTX
CSS - Text Properties
PPT
Lesson 3 - HTML & CSS Part 2
PPTX
Lesson1 - Fall 2013
PPTX
Lesson2
PPTX
CSS Layout Tutorial
PPTX
Introduction to CSS3
PPTX
Sprites rollovers
PDF
Building a Website from Planning to Photoshop Mockup to HTML/CSS
PPTX
Lecture4
PPTX
Tutorial1 - Part 2
PDF
Tutorial1
PDF
Project1
PPTX
Lesson 3
PPTX
Lesson2
PPTX
Lesson1
PDF
Heather Strycharz - Resume
CSS - Text Properties
Lesson 3 - HTML & CSS Part 2
Lesson1 - Fall 2013
Lesson2
CSS Layout Tutorial
Introduction to CSS3
Sprites rollovers
Building a Website from Planning to Photoshop Mockup to HTML/CSS
Lecture4
Tutorial1 - Part 2
Tutorial1
Project1
Lesson 3
Lesson2
Lesson1
Heather Strycharz - Resume

Recently uploaded (20)

PPTX
YV PROFILE PROJECTS PROFILE PRES. DESIGN
PPT
Machine printing techniques and plangi dyeing
PPT
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
PPTX
Complete Guide to Microsoft PowerPoint 2019 – Features, Tools, and Tips"
PPTX
12. Community Pharmacy and How to organize it
PDF
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
PPTX
areprosthodontics and orthodonticsa text.pptx
PPTX
Media And Information Literacy for Grade 12
PDF
The Advantages of Working With a Design-Build Studio
PPTX
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PPTX
AD Bungalow Case studies Sem 2.pptxvwewev
PPTX
Entrepreneur intro, origin, process, method
PDF
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
PPTX
Wisp Textiles: Where Comfort Meets Everyday Style
PDF
Urban Design Final Project-Site Analysis
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
PPTX
Special finishes, classification and types, explanation
PPT
UNIT I- Yarn, types, explanation, process
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
YV PROFILE PROJECTS PROFILE PRES. DESIGN
Machine printing techniques and plangi dyeing
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
Complete Guide to Microsoft PowerPoint 2019 – Features, Tools, and Tips"
12. Community Pharmacy and How to organize it
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
areprosthodontics and orthodonticsa text.pptx
Media And Information Literacy for Grade 12
The Advantages of Working With a Design-Build Studio
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
AD Bungalow Case studies Sem 2.pptxvwewev
Entrepreneur intro, origin, process, method
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
Wisp Textiles: Where Comfort Meets Everyday Style
Urban Design Final Project-Site Analysis
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
Special finishes, classification and types, explanation
UNIT I- Yarn, types, explanation, process
DOC-20250430-WA0014._20250714_235747_0000.pptx

CSS3 Transitions

  • 2. CSS Transitions Introduction CSS Transitions allow property changes in CSS values to occur smoothly over a specified duration. This smoothing animates the changing of a CSS value when triggered by a mouse click, focus or active state, or any changes to the element (including even a change on the element’s class attribute).
  • 3. Basic Rollover HTML: <a href="#" class="button">Transition me!</a> CSS: a.button { padding: 5px 10px; background: #4EBFBF; color: #fff; text-decoration: none; } a.button:hover { background: #690; }
  • 4. Basic Rollover with Transition HTML: <a href="#" class="button">Transition me!</a> CSS: a.button { padding: 5px 10px; background: #4EBFBF; color: #fff; text-decoration: none; -moz-transition-property: background; -moz-transition-duration: 0.3s; -moz-transition-timing-function: ease; } a.button:hover { background: #690; }
  • 5. Basic Rollover with Transition background: #4EBFBF; transition-property: background; transition-duration: 0.3s; transition-timing-function: ease; transition-property: The property to be transitioned (in this case, the background property) transition-duration: How long the transition should last (0.3 seconds) transition-timing-function: How fast the transition happens over time (ease)
  • 6. Timing Function transition-timing-function: ease; The timing function value allows the speed of the transition to change over time by defining one of six possibilities: ease, linear, ease-in, ease-out, ease-in-out, and cubic- bezier (which allows you to define your own timing curve).
  • 7. Timing Function If you slept through geometry in high school like I did, don’t worry. I recommend simply plugging in each of these timing function values to see how they differ. …For longer animations, the timing function you choose becomes more of an important piece of the puzzle, as there’s time to notice the speed changes over the length of the animation. When in doubt, ease (which is also the default value) or linear should work just fine for short transitions. - Dan Cederholm http://www.alistapart.com/articles/understanding-css3-transitions
  • 8. Shorthand Code transition-property: background; transition-duration: 0.3s; transition-timing-function: ease; Is the same as: transition: background 0.3s ease;
  • 9. Browser Compatibility The transition property is not supported in any browsers. Firefox 4 supports an alternative, the -moz-transition property. Safari and Chrome support an alternative, the -webkit-transition property. Opera supports an alternative, the -o-transition property. -webkit-transition: background 0.3s ease; -moz-transition: background 0.3s ease; -o-transition: background 0.3s ease; transition: background 0.3s ease;
  • 11. Wouldn’t it make more sense if the transition properties were placed in the :hover declaration, since that’s the trigger for the transition? The answer is that there are other possible states of an element besides :hover, and you’ll likely want that transition to happen on each of those without duplication. For instance, you may want the transition to also happen on the :focus or :active pseudo-classes of the link as well. Instead of having to add the transition property stack to each of those declarations, the transition instructions are attached to the normal state and therefore declared only once. - Dan Cederholm http://www.alistapart.com/articles/understanding-css3-transitions
  • 12. Transitioning multiple properties Let’s say that along with the background color, we also want to change the link’s text color and transition that as well. We can do that by stringing multiple transitions together, separated by a comma. Each can have their varying duration and timing functions . a.button { padding: 5px 10px; background: #4EBFBF; color: #fff; -webkit-transition: background .3s ease, color 0.2s linear; -moz-transition: background .3s ease, color 0.2s linear; -o-transition: background .3s ease, color 0.2s linear; transition: background .3s ease, color 0.2s linear; } a.button:hover, a.button:focus { color: #030; background: #690; } Text via: http://www.alistapart.com/articles/understanding-css3-transitions
  • 13. Transitioning multiple properties An alternative to listing multiple properties is using the all value. This will transition all available properties. Let’s drop all into our simple example instead of listing background and color separately. They’ll now share the same duration and timing function. a.button { padding: 5px 10px; background: #4EBFBF; color: #fff; -webkit-transition: all 0.3s ease; -moz-transition: all 0.3s ease; -o-transition: all 0.3s ease; transition: all 0.3s ease; } a.button:hover, a.button:focus { color: #030; background: #690; } Text via: http://www.alistapart.com/articles/understanding-css3-transitions
  • 14. Example B: div.exampletransitionb { CSS width: 520px; } div.exampletransitionb div { background-color: #ED8029; border-radius: 5px 5px 5px 5px; color: white; margin: 5px 0; padding: 5px; text-align: right; width: 100px; } div.exampletransitionb:hover div { width: 500px; } div.exampletransitionb div.ease { -moz-transition: all 3s ease 0s; <div class="exampletransitionb"> HTML } div.exampletransitionb div.linear { <div class="ease">ease</div> -moz-transition: all 3s linear 0s; } <div class="linear">linear</div> div.exampletransitionb div.easein { <div class="easein">ease-in</div> -moz-transition: all 3s ease-in 0s; <div class="easeout">ease-out</div> } <div class="easeinout">ease-in-out</div> div.exampletransitionb div.easeout { -moz-transition: all 3s ease-out 0s; </div> } div.exampletransitionb div.easeinout { -moz-transition: all 3s ease-in-out 0s; } Example via: http://www.css3.info/preview/css3-transitions/
  • 17. Further Reading www.alistapart.com/articles/understanding-css3-transitions http://www.w3schools.com/css3/css3_transitions.asp http://www.impressivewebs.com/css3-transitions-without-hover http://www.netmagazine.com/tutorials/more-efficient-css3-transitions http://en.wikipedia.org/wiki/12_basic_principles_of_animation