To create a hidden overflow that becomes visible on mouse hover, you can use the following CSS code snippet. The 16px padding is included to prevent text from re-wrapping when the scrollbar appears.
div.myautoscroll {
height: 40ex;
width: 40em;
overflow: hidden;
border: 1px solid #444;
margin: 3em;
}
div.myautoscroll:hover {
overflow: auto;
}
div.myautoscroll p {
padding-right: 16px;
}
div.myautoscroll:hover p {
padding-right: 0px;
}
You can test this functionality in action by visiting this fiddle. Make sure to adjust the window size to see the full effect.
Last updated on October 23, 2014:
Due to variation in how scrollbars are displayed across systems and browsers, you may need to tweak the 16px padding to suit your setup. Some systems like newer Mac OS versions only show scrollbars when scrolling begins, which could affect this technique. In such cases, consider leaving the overflow as auto or adjusting based on your specific requirements.