flex-basis - HTML CSS CSS Animatable Property

HTML CSS examples for CSS Animatable Property:flex-basis

Introduction

In the following code the flex-basis property of the flex item2 is animating from its initial value "100px" to "200px", and back to the initial value "100px" again up to infinite times.

-webkit- prefix is for Chrome, Safari, Opera.

-moz- prefix is for Firefox.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of CSS3 flex-basis Property Animation</title>
  <style type="text/css">
.flex-container {<!--   w  w  w .  j  av  a 2 s  .  c  o m-->
  width: 300px;
  height: 200px;
  font-size: 32px;
  border: 1px solid black;
  display: -webkit-flex; /* Safari */
  display: flex; 
}
.flex-container div {
  -webkit-flex-basis: 100px; /* Safari 6.1+ */
    -ms-flex-basis: 100px; /* IE 10 */
      flex-basis: 100px; 
}
.item1 {
  background: red;
}
.item2 {
  background: blue;
}
.animated {
    -webkit-animation: test 4s infinite; 
    animation: test 4s infinite;
}

@-webkit-keyframes test {
    50% {-webkit-flex-basis: 200px;}
}

@keyframes test {
    50% {flex-basis: 200px;}
}
</style>
 </head>
 <body>

  <p> </p>
  <div class="flex-container">
   <div class="item1">
    1
   </div>
   <div class="item2 animated">
    2
   </div>
  </div>
 </body>
</html>

Related Tutorials