I’m working on an animation where I want diagonal lines to grow from their initial height of 0% to 100%, without any rotation. Currently, I have the following CSS code:
HTML
<div class="stripes-1">
<span class="rec-1"></span>
<span class="rec-1"></span>
<span class="rec-1"></span>
<span class="rec-1"></span>
</div>
CSS
.who-we-are {
height: 100vh;
margin: auto;
padding: auto;
}
.stripes-1 {
display: flex;
flex-direction: column;
}
.rec-1 {
transform: scaleX(100%) rotate(40deg);
animation: expandHeight 1s ease-in-out forwards;
width: 72.5%;
margin: 1rem 0;
animation: appearUp 1.5s linear;
transition: ease-in ;
position: relative;
left: 500px;
top: 350px;
}
@keyframes appearUp{
0%{
transform:scaleX(0) rotate(0deg);
}
100%{
transform: scaleX(100%) rotate(40deg);
}
}
.rec-1:nth-of-type(1){
border-bottom: 30px solid #1DCDFE;
}
.rec-1:nth-of-type(2) {
border-bottom: 30px solid #11FFC4;
}
.rec-1:nth-of-type(3) {
border-bottom: 30px solid #21D0B2;
}
.rec-1:nth-of-type(4) {
border-bottom: 30px solid #2F455C;
}
The issue is that the lines not only grow but also rotate during the animation. However, I want them to maintain their initial angle of 40 degrees and grow vertically. I’ve tried adjusting the transform-origin property and adding separate animations, but I couldn’t achieve the desired result.
Could someone please guide me on how to modify the CSS animation to make the lines grow from the initial angle of 40 degrees without rotation?
Updated HTML and CSS
3
Answers
This
transform: scaleX(100%) rotate(40deg);
and thistransform: rotate(40deg) scaleX(100%);
– it is not the same thing.To modify the CSS animation and make the lines grow from the initial angle of 40 degrees without rotation, you can adjust the transform properties in the keyframes animation. Here’s an updated version of your CSS code:
In this updated code, we’re using the
::before
pseudo-element to create the growing lines. We set theposition
of.rec-1
torelative
to create a positioning context for the pseudo-element.The
::before
pseudo-element hasposition: absolute
and is positioned at the bottom left corner of.rec-1
usingbottom: 0
andleft: 0
. Its initial width is set to 0, and the height is set to 30px to match the border thickness you specified.We use
transform: scaleX(0)
to initially scale the width of the pseudo-element to 0, effectively hiding it. By settingtransform-origin: left bottom
, we ensure the growth starts from the bottom left corner.The animation is applied using
animation: line-growth 1.5s linear
, whereline-growth
is the name of the keyframes animation, and1.5s
is the duration. We set it tolinear
to achieve a consistent growth rate.Each
.rec-1
element has a differentbackground-color
specified to match the styles you’ve set in your original code.With these modifications, the lines will grow vertically from the bottom left corner without rotation. Feel free to adjust the width, height, colors, and animation properties as needed.
1- i set align-items: flex-start on the .stripes-1 container to align the lines to the left side.
2- The height property of .rec-1 is initially set to 0, and we animate it to 100% using the expandHeight animation.
3- i removed the unnecessary transform and animation properties that were causing the rotation and unwanted effects.
4- The border color is set for each nth-of-type element using the border-color property instead of border-bottom, and the border-bottom color is set to transparent initially.
With these modifications, the lines will grow vertically from their initial angle of 40 degrees without any rotation. Feel free to adjust the margins and other properties to fit your animation requirements.