如何在一个div中隐藏滚动条

7
我已经创建了一个 div,用于包装溢出的内容并使其可滚动,但我希望其滚动条被隐藏而 div 仍可滚动。
.description
{
    height: 150px;
    overflow: scroll;
}

<div class="description">
    <h4>Description</h4>
    <p>After a series of deadly discoveries, Bruce Wayne has learned that the Court of Owls is real � and a deadly threat out to control Gotham City! Unleashing their deadly assassins known as the Talons, Batman must stop the insidious Court of Owls before they claim the city for their own. In doing so, The Dark Knight will uncover dark secrets � not just about the city he�s sworn to protect, but about the history of the Wayne family.After a series of deadly discoveries, Bruce Wayne has learned that the Court of Owls is real � and a deadly threat out to control Gotham City! Unleashing their deadly assassins known as the Talons, Batman must stop the insidious Court of Owls before they claim the city for their own. In doing so, The Dark Knight will uncover dark secrets � not just about the city he�s sworn to protect, but about the history of the Wayne family.After a series of deadly discoveries, Bruce Wayne has learned that the Court of Owls is real � and a deadly threat out to control Gotham City! Unleashing their deadly assassins known as the Talons, Batman must stop the insidious Court of Owls before they claim the city for their own. In doing so, The Dark Knight will uncover dark secrets � not just about the city he�s sworn to protect, but about the history of the Wayne family.</p>
</div>

1
你可以像这样做 https://jsfiddle.net/Lg0wyt9u/1438/,我在Mozilla上测试过了。 - Nenad Vracar
1个回答

16

您可以使用 3行CSS 来隐藏滚动条,这将在所有不同的浏览器中起作用。尝试以下CSS[更新]

CSS:

.classname {
  height: 150px;
  overflow: scroll;
  -ms-overflow-style: none;
  /* for Internet Explorer, Edge */
  scrollbar-width: none;
  /* for Firefox */
}

.classname::-webkit-scrollbar {
  display: none;
  /* for Chrome, Safari, and Opera */
}

JSFiddle : https://jsfiddle.net/xet3r59k/3/


你能告诉我这个在其他浏览器如火狐或IE中也能正常工作吗? - Yash Jain
你试过这个了吗? - user2297037
除了 Chrome 浏览器,这在任何其他浏览器上都不起作用。 - Digggid

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接