w3resource

CSS Properties: How to set the border-left-width animatable?

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html><!-- Declaration of HTML5 document type -->
<html>
<head>
<title>How to set the border-left-width animatable</title><!-- Title of the HTML document -->
<style type="text/css">
/* CSS styling */
#mydiv {
width: 200px;
height: 150px;
border: 1px solid #CC63FF; /* Sets the border style for the 'mydiv' element */
-webkit-animation: mymove 5s infinite; /* Initiates an animation with CSS for WebKit browsers */
animation: mymove 5s infinite; /* Initiates an animation with CSS for all browsers */
}
@keyframes mymove { /* Defines a keyframe animation called 'mymove' */
50% {border-left-width: 15px;} /* Specifies that at 50% of the animation duration, the left border width of the 'mydiv' element should be 15 pixels */
}
</style>
</head>
<body>
<p>w3resource Tutorial</p><!-- Paragraph content -->
<div id="mydiv">Border left width animatable</div><!-- Div element with the left border width set to be animatable -->
</body>
</html>

Explanation:

  • This HTML document demonstrates how to create an animatable border-left-width effect using CSS animations.
  • The mydiv element is styled with a border that has a solid style and a color of #CC63FF.
  • An animation called mymove is defined using CSS keyframes. It specifies that at 50% of the animation duration, the left border width of the mydiv element should be 15 pixels.
  • The animation is applied to the mydiv element, causing the left border width to change dynamically over a period of 5 seconds and repeat infinitely.
  • As a result, the left border width of the mydiv element will animate between its initial width and 15 pixels, creating a visually appealing effect.

Live Demo:

See the Pen border-left-width-animatable-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes No

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.