Creating a left, down, left line drawing animation using only CSS

Utilizing CSS transitions to animate a line drawing from right to left, then down, and finally continuing to load to the left:

point 1------point 2 
               |
               |
               |
               ---------point 3

Here is the CSS code I am using:

.transitionLine {
  height:0px;
  width:1px;
  border:10px solid #ef4e4e;
  
  -webkit-animation: increase 3s;
  -moz-animation:    increase 3s; 
  -o-animation:      increase 3s; 
  animation:         increase 3s; 
  animation-fill-mode: forwards;
}

@keyframes increase {
/* Load to the left */
30% {
width: 500px;
}
/* Load down */
60% {
border-radius: 3px;
width: 1000px;
}
/* Load to the left */
100% {
border-radius: 3px;
width: 1500px;
}
}
<div class="transitionLine"></div>

My CSS does not break the line to load down and left, how can I fix this issue?

Answer №1

To achieve this particular effect, you can refer to the snippet provided below.
The implementation involves the use of two keyframes along with an after property to create a bottom line.

.transitionLine {
    height: 0px;
    width: 1px;
    border-top: 10px solid #ef4e4e;
    border-right: 10px solid #ef4e4e;
    position: relative;
    -webkit-animation: increase 3s;
    -moz-animation: increase 3s;
    -o-animation: increase 3s;
    animation: increase 3s;
    animation-fill-mode: forwards;
}

.transitionLine:after {
    content: '';
    display: block;
    height: 0px;
    width: 1px;
    border-top: 10px solid #ef4e4e;
    border-right: 10px solid #ef4e4e;
    -webkit-animation: increase2 3s;
    -moz-animation: increase2 3s;
    -o-animation: increase2 3s;
    animation: increase2 3s;
    animation-fill-mode: forwards;
    position: absolute;
    left: 100%;
    bottom: 0;
}

@keyframes increase {
    30% {
        width: 200px;
        height: 0px;
    }
    31% {
        width: 200px;
        height: 1px;
    }
    60% {
        height: 100px;
        width: 200px;
    }
    100% {
        height: 100px;
        width: 200px;
    }
}

@keyframes increase2 {
    60% {
        height: 0px;
        width: 0px;
    }
    100% {
        height: 0px;
        width: 200px;
    }
}
<div class="transitionLine"></div>

Answer №2

You can create stunning line animations using gradients with just one keyframe:

.transitionLine {
  width:300px;
  height:100px;
  background-image:
   linear-gradient(#ef4e4e,#ef4e4e),
   linear-gradient(#ef4e4e,#ef4e4e),
   linear-gradient(#ef4e4e,#ef4e4e);
  background-size:
    0% 5px,
    5px 0%,
    0% 5px;
  background-position:
    top left,
    top center,
    150px 100%;
  background-repeat:no-repeat;
  animation: increase 3s;
  animation-fill-mode: forwards;
}

@keyframes increase {
  30% {
    background-size:
    50% 5px,
    5px 0%,
    0% 5px;
  }
  /*load down*/
  60% {
    background-size:
    50% 5px,
    5px 100%,
    0% 5px;
  }
  /*load to left*/
  100% {
    background-size:
    50% 5px,
    5px 100%,
    50% 5px;
  }
}
<div class="transitionLine"></div>

You have the flexibility to scale this effect to include any number of lines:

.transitionLine {
  width:300px;
  height:100px;
  background-image:
   linear-gradient(#ef4e4e,#ef4e4e),
   linear-gradient(#ef4e4e,#ef4e4e),
   linear-gradient(#ef4e4e,#ef4e4e),
   linear-gradient(#ef4e4e,#ef4e4e),
   linear-gradient(#ef4e4e,#ef4e4e);
  background-size:
    5px 0%,
    0% 5px,
    5px 0%,
    0% 5px,
    5px 0%;
  background-position:
    bottom left,
    top left,
    top center,
    150px 100%,
    right bottom;
  background-repeat:no-repeat;
  animation: increase 3s;
  animation-fill-mode: forwards;
}

@keyframes increase {
  20% {
    background-size:
    5px 100%,
    0% 5px,
    5px 0%,
    0% 5px,
    5px 0%;
  }
  40% {
    background-size:
    5px 100%,
    50% 5px,
    5px 0%,
    0% 5px,
    5px 0%;
  }
  60% {
    background-size:
    5px 100%,
    50% 5px,
    5px 100%,
    0% 5px,
    5px 0%;
  }
  80% {
    background-size:
    5px 100%,
    50% 5px,
    5px 100%,
    50% 5px,
    5px 0%;
  }
  100% {
    background-size:
    5px 100%,
    50% 5px,
    5px 100%,
    50% 5px,
    5px 100%;
  }
}
<div class="transitionLine"></div>

Answer №3

.dynamicLine {
    height:0px;
    width:1px;
    border:10px solid #ef4e4e;
    -webkit-animation: growHeight 1s;
    -moz-animation:    growHeight 1s; 
    -o-animation:      growHeight 1s; 
    animation:         growHeight 1s; 
    animation-fill-mode: forwards;
}
.dynamicLine:before{
    height: 0px;
    content: " ";
    width: 0px;
    border: 10px solid #ef4e4e;
    -webkit-animation: growHeightA 1s;
    -moz-animation: growHeightA 1s;
    -o-animation: growHeightA 1s;
    animation: growHeightA 1s;
    animation-fill-mode: forwards;
    margin: -10px 0 0 510px;
    animation-delay: 1s;
    display: inline-block;
    opacity: 0;
}
.dynamicLine:after{
    height: 0px;
    content: " ";
    width: 0px;
    border: 10px solid #ef4e4e;
    -webkit-animation: growWidthB 1s;
    -moz-animation: growWidthB 1s;
    -o-animation: growWidthB 1s;
    animation: growWidthB 1s;
    animation-fill-mode: forwards;
    margin: 0px 0 0 510px;
    animation-delay: 2s;
    display: inline-block;
    opacity: 0;
}

@keyframes growHeight {
    0% {       
        width: 0px;
    }
    100% {
        width: 500px;
    } 
}
@keyframes growHeightA {
    0% {       
        height: 0px;
        opacity: 1;
    }
    100% {
        height: 500px;
        opacity: 1;
    } 
}
@keyframes growWidthB {
    0% {       
        width: 0px;
        opacity: 1;
    }
    100% {
        width: 500px;
        opacity: 1;
    } 
}





<div class="dynamicLine"></div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Different strategies for displaying a singular pie chart on multiple pages

I have implemented a pie chart on an HTML page and now I want to display this chart on multiple other HTML pages. Below is the JavaScript code for creating the pie chart: function piechart() { var chart; var legend; ...

The Safari browser is having trouble rendering the website's CSS and HTML properly

Check out this example of how the website should look on Chrome for Android: https://i.stack.imgur.com/RzUSp.jpg And here is an example from Safari on iPad Mini 2: https://i.stack.imgur.com/PAj2i.jpg The Safari version doesn't display the proper fon ...

Styling the first child element within a list using the li tag

<ul> <li class="bla">aaa</li> <li class="my_li">sss</li> <li class="my_li">ddd</li> <li class="my_li">fff</li> </ul> css: .my_li:first-child{ ...

html - Removing excess space following the footer

Having trouble getting rid of the excess white space below my footer on this website: I attempted to search for a solution online and even added padding:0; to the footer's CSS, but unfortunately it didn't solve the issue. Appreciate any assista ...

Words fail to display

.sport { content: url("../img/sport.png"); background-color: rgba(0,0,0,1.0); top: 61px; height: 310px; width: 300px; position: absolute; margin: 0; left: 0; border-radius: 4px; overflow: hidden; } .sportsandactivis { background-colo ...

What's the Best Way to Add a Border to My Two-Column Form?

I'm currently working on a reservation form for my website with a 2-column layout. In one column, I have tables, and I've been trying to add a divider between the columns but haven't found a solution yet. Despite researching ways to add a d ...

Trouble with CSS transitions not functioning while altering React state

Each time a user clicks on an accordion, the content should smoothly show or hide with a transition effect. However, the transition only seems to work when opening a closed accordion, not when closing an already open one! To get a clearer idea of this iss ...

An unusual html element

During a recent exploration of a website's code using the inspect tool, I stumbled upon a tag that was completely unfamiliar to me. <gblockquote></gblockquote> I've come across a blockquote before, but never a gblockquote. Interest ...

Is there a way to customize the checkout page using JavaScript?

I'm working on a checkout page where fields need to change based on a selected radio button. There are two options: A and B. When A is selected, I want certain fields to remain visible while others disappear, and vice versa for option B. Although I p ...

Tips for making a div with a single triangular side using Reactjs

Hey there, I'm looking to design a header similar to the one shown in this image. Can someone provide guidance on how I can achieve this UI using React.js? https://i.sstatic.net/zmW5x.jpg ...

Absolute positioning causes a 100% height container to be displaced from the IE viewport

While my code works seamlessly in Firefox and Safari, Internet Explorer presents a challenge I cannot seem to solve. The Problem: In non-IE browsers, the container displays properly with space around the edges of the viewport. However, in IE, the containe ...

Troubleshooting: Issue with multiple file input elements on page - only the first input is functional and not displaying preview images

Having some trouble with loading multiple file inputs and their preview images. I've tried using getElementsByClassName but I suspect that I'm not iterating over them correctly. I want to avoid using unique IDs for the elements because they will ...

Using Visual Studio Code to envelop your HTML code is a great way

I have a paragraph, <p> hello world</p> and I'm interested in enclosing the word "world" within <em></em> tags. I am searching for an easy way to highlight the word and insert the <em> tags without having to remove and re ...

Is there an advantage to pre-rendering a circle on an HTML5 canvas for improved performance?

Is it more efficient to pre-render graphics for a basic shape like a circle on an off-screen canvas? Would there be noticeable improvements in rendering performance when dealing with 100 circles at game-like framerates? What about 50 circles or just 25? ...

Unable to choose multiple options within a selection field

My webgui testing involves the use of selenium, which includes the following method: protected static selectListItems(String id, String value1, String value2, String value3,String value4){ String values = "" if(StringUtils.isNotBlank(value1)) ...

Using jQuery to highlight the navigation menu when a specific div scrolls into view

I have implemented a side navigation consisting of circular divs. Clicking on one scrolls you to the corresponding .block div, and everything functions correctly. However, I am now curious if it is feasible to highlight the relevant .nav-item div based on ...

Beautiful ExpressionChangedAfterItHasBeenCheckedError

I need your help Input field where I can enter a Student email or IAM, which will be added to a string array List displaying all the students I have added, using a for loop as shown below Delete button to remove a student from the array The list has a sp ...

Ways to adjust dimensions depending on zoom level or screen size

Here is the HTML code snippet: <div id="divMainFirst"> <div id="divInnerFirst"> <div id="divTitleHeaderUC"> <span id="spanTitleHeaderUC">Urgent Care Wait Time</span> </d ...

What is the process for inserting or removing a row with Javascript?

Currently, I am in the process of working on some HTML/PHP code which is displayed below. <h3 style="text-align:center;margin-top:45px;">Sitting Days</h3> <div class="sitting-days" style="display:flex; justify-content:center; margin-bottom ...

Customizing default elements in A-frame: Tips and Tricks

One of the default components attached to an A-frame entity is rotation and position. I am looking to customize these components and apply the changes to the entities. For instance, I would like to create a new component called "positionnew" with a differ ...