<div class="flex">
  <div class="block"></div>
  <div class="block"></div>
  <div class="block"></div>
</div>
*{
  margin: 0;
  padding: 0
}

.flex{
  display: flex;
  justify-content: space-between;
}
 

.block{
  --lineOffset: 0;
  position: relative;
  width: 50px;
  height: 50px;
  background-color: red;
}
.block::after{
    z-index: 1000;
    content: '';
    display: block;
    position: absolute;
    left: 0;
    bottom: 0;
    height: 5px;
    width: 0;
    background-color: green;
    transition: width 1s ease
}
.block:hover::after{
    width: calc(100vw - var(--lineOffset));  
}
const setBlocksVars = () => {
  document.querySelectorAll('.block').forEach(block => {
    block.style.setProperty('--lineOffset', block.offsetLeft + 'px')
  })
}

setBlocksVars()

let resizeDelay
window.addEventListener('resize', () => {
  clearInterval(resizeDelay)
  resizeDelay = setTimeout(setBlocksVars, 1000)
})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.