JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container">
<div class="text">Your very and very long text here</div>
<div class="scrollbar-width"></div>
</div>
CSS
.container {
display: flex;
width: 100px;/*to make scrollbar necessary*/
height: 30px;/*to make scrollbar necessary*/
border: 1px solid blue;
}
.text {
flex: 1;
float: left;
overflow-y: hidden;
}
.scrollbar-width {
float: left;
overflow-x: hidden;
overflow-y: scroll;
visibility: hidden;
}
.scrollbar-width::-webkit-scrollbar { /* for debugging */
background-color: red;
}
.text:hover {
overflow-y: scroll;
}
.text:hover + .scrollbar-width {
display: none;
}