I have a div whose height and width will be dynamic. I am trying to have a dotted animation frame for this div. The problem I am facing is the duration of the animation is not relative to the height and width. that is, regardless of the height and width, its animation should be at the same speed in all angles
.dynamic { position: absolute; height: 30px; width: 300px; overflow: hidden } .dynamic::before { animation: slideDash 2.5s infinite linear; position: absolute; content: ''; left: 0; right: 0; outline: 1px dashed #fff; box-shadow: 0 0 0 1px rgb(23, 163, 102); width: 200%; } .dynamic::after { animation: slideDash 2.5s infinite linear reverse; position: absolute; content: ''; right: 0; bottom: 0; outline: 1px dashed #fff; left: 0; box-shadow: 0 0 0 1px rgb(23, 163, 102); width: 200%; } .dynamic div::before { animation: slideDashRev 2.5s infinite linear reverse; position: absolute; content: ''; top: 0; bottom: 0; outline: 1px dashed #fff; box-shadow: 0 0 0 1px rgb(23, 163, 102); height: 200%; } .dynamic div::after { animation: slideDashRev 2.5s infinite linear; position: absolute; content: ''; top: 0; bottom: 0; outline: 1px dashed #fff; right: 0; box-shadow: 0 0 0 1px rgb(23, 163, 102); height: 200%; } @keyframes slideDash { from { transform: translateX(-50%); } to { transform: translateX(0%); } } @keyframes slideDashRev { from { transform: translateY(-50%); } to { transform: translateY(0%); } }
<div class="dynamic"> <div></div> </div>
source share