我正在做一个Web项目,我需要定制容器元素的外观和行为.具体地说,我想从容器中删除滚动条,并防止用户 Select 其中的文本.我try 了各种CSS属性和技术,但我还没有找到一个在不同浏览器中可靠工作的解决方案.
以下是我迄今为止try 的:
<div class="custom-container">
<!-- Content goes here -->
</div>
CSS:个
.custom-container {
width: 300px;
height: 200px;
overflow: hidden; /* Hides scroll bars, but still allows scrolling */
user-select: none; /* Prevents text selection, but doesn't work consistently */
}
虽然设置为overflow: hidden
可以成功隐藏滚动条,但它仍然允许用户使用鼠标或touch 手势滚动内容.此外,user-select: none
属性阻止文本 Select ,但并不是所有浏览器都统一支持它.
Could someone suggest a reliable CSS-based solution to achieve both hiding scroll bars and preventing text selection within the container element? Any insights or alternative approaches would be greatly appreciated!