I have a CSS class that on hover should change the justify-content
property from center
to flex-start
with a delay of 1s.
So everything works fine and is being delayed except from the justify-content
.
.menuItem:hover {
transition-property: all;
transition-delay: 1s;
justify-content: flex-start;
}
Am I doing something wrong? And If so, how can I achieve that behavior?
justify-content is not a transition-able property. You can find the full list of compatible properties here. All unlisted properties should simply snap to their new value. If you happen to need to animate a single element only, you may try using absolute positioning.
The justify-content property aligns the flexible container's items when the items do not use all available space on the main-axis (horizontally). Tip: Use the align-items property to align the items vertically.
justify-content
is not a transition-able property. You can find the full list of compatible properties here. All unlisted properties should simply snap to their new value.
If you happen to need to animate a single element only, you may try using absolute positioning.
#wrapper {
position: relative;
}
#element {
position: absolute;
left: 50%;
transform: translateX(-50%);
transition: all 300ms;
}
#element:hover {
left: 0;
transform: translateX(0);
}
Keep in mind that this will not work for multiple elements.
You can achieve your goal with two flex items, where the transition is on the "flex" property.
.container {
display: flex;
justify-content: center;
border: 1px solid gray;
}
.content {
flex: 1;
max-width: fit-content;
border: 1px solid orangered;
}
.dummy {
flex: 0;
transition: flex 1s;
border: 1px solid limegreen;
}
.container:hover .hovered {
flex: auto;
}
<div class="container">
<div class="content"> hover over me </div>
<div class="dummy hovered" />
</div>
Hey Fabricio, this section is for your question. Cheers
.container {
display: flex;
justify-content: center;
border: 1px solid gray;
}
.content {
width: fit-content;
border: 1px solid orangered;
}
.dummy {
transition: flex 1s;
border: 1px solid limegreen;
}
.after {
flex-grow: 1;
}
.before {
flex-grow: 0;
}
.container:hover .before {
flex-grow: 1;
}
<div class="container">
<div class="dummy before" ></div>
<div class="content"> hover over me </div>
<div class="dummy after" ></div>
</div>
You can't animate 'justify-content', but if you need to animate element to move from one side to other, you can do:
.parent {
display: flex;
}
.menuItem:hover {
flex: 1;
animation: moveAnim .3s alternate 1;
}
@keyframes moveAnim {
from { flex: none }
to{ flex: 1 }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With