html - Prevent text from shifting when hovered -
i'm new flexbox , trying make menu using it.
i want links have nice border on bottom when user hovers on them. if set box-sizing: border-box; flex keeps recalculating text position , element 'jumps' instead of predicted behaviour.
i have example problem. don't want content inside element jump when hover.
is there simple solution/edition code make work expected? know other ways of achieving want: set baseline, use relative/absolute positioning...
.item {    display: flex;    width: 200px;    height: 100px;    background: #123;    color: #fff;    text-align: center;    justify-content: center;    flex-direction: column;  }  .item:hover {    border-bottom: 10px solid lightgreen;    box-sizing: border-box;  }  <div class="item">    content  </div>  
by adding 10px border on hover, changing size of box on hover. reposition surrounding elements... on hover.
one solution reserve space border @ times. in other words, have 10px border factored element in normal state.
this border gets element's background color (or transparent) not visible. on hover, change color.
.item {    display: flex;    width: 200px;    height: 100px;    background: #123;    color: #fff;    text-align: center;    justify-content: center;    flex-direction: column;    position: relative;  }  .item::after {    content: "";    position: absolute;    bottom: 0;    left: 0;    width: 100%;    border-bottom: 10px solid #123;  }  .item:hover::after {    border-bottom: 10px solid lightgreen;  }  <div class="item">content</div>  
Comments
Post a Comment