我實際上是在嘗試複製通常在移動應用中看到的水平滾動菜單。如何創建水平隱藏滾動條
我真的不明白爲什麼它不應該工作,但對我來說,隱藏垂直滾動條和水平滾動似乎是合乎邏輯的。我知道隱藏垂直滾動條有很多解決方案,但爲什麼水平滾動條不可能這樣做?
這是我迄今爲止創建的代碼片段,演示了垂直方式,但是如何修改水平方向?
我嘗試過:
overflow-y:hidden; overflow-x:scroll;
,但沒有奏效...
我可以把它彎曲到jQuery的,但是蔭不知道如何去這樣的說法,所以如果有一個兼容CSS的解決方案,這將幫助我。
.block,
.container {
width: 250px;
height: 250px;
}
.container {
border: 1px solid #aaa;
padding: 5px 0 5px 5px;
position: relative;
overflow: hidden;
}
.container-inner {
position: absolute;
overflow-x: hidden;
overflow-y: scroll;
}
@media screen and (-webkit-min-device-pixel-ratio: 0) {
.container-inner,
.block {
transform: scale(-1, 1);
-webkit-transform: scale(-1, 1);
}
.container-inner {
right: 0;
}
}
.block {
padding: 10px 0px 10px 0;
}
<div class="container">
<div class="container-inner">
<div class="block">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vehicula quam nibh, eu tristique tellus dignissim quis. Integer condimentum ultrices elit ut mattis. Praesent rhoncus tortor metus, nec pellentesque enim mattis nec.
<br/>
<br/>Nulla vitae turpis ut dui consectetur pellentesque quis vel est. Curabitur rutrum, mauris ut mollis lobortis, sem est congue lectus, ut sodales nunc leo a libero. Cras quis sapien in mi fringilla tempus condimentum quis velit. Aliquam id aliquam
arcu. Morbi tristique aliquam rutrum.
<br/>
<br/>Duis tincidunt, orci suscipit cursus molestie, purus nisi pharetra dui, tempor dignissim felis turpis in mi. Vivamus ullamcorper arcu sit amet mauris egestas egestas. Vestibulum turpis neque, condimentum a tincidunt quis, molestie vel justo.
<br/>
<br/>Sed molestie nunc dapibus arcu feugiat, ut sollicitudin metus sagittis. Aliquam a volutpat sem. Quisque id magna ultrices, lobortis dui eget, pretium libero. Curabitur aliquam in ante eu ultricies. Quisque vitae tincidunt purus. Vivamus feugiat
bibendum erat, nec interdum urna porta sed.
<br/>
<br/>Nunc lobortis neque orci, ut suscipit nisl congue feugiat. Vivamus feugiat tellus quis cursus sollicitudin. Curabitur dolor massa, dictum ut ipsum in, porttitor pellentesque ante. Aenean egestas cursus tempor. Maecenas semper tortor sit amet egestas
cursus. Mauris porttitor quis nisi ut tincidunt. Curabitur adipiscing eleifend nibh. Praesent mauris leo, consequat vitae orci eget, vestibulum bibendum nisi. Aliquam tempus diam ut tortor cursus, eget sodales augue adipiscing. Nulla at dignissim
libero.
</div>
</div>
</div>
謝謝,這真是太棒了!我想問的兩件事情是,這可能與其他瀏覽器兼容,我能否介紹移動設備的滾動功能? – Krys
@Krystyna這個工程跨瀏覽器,你可以使用[** media query's **](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries)來控制小屏幕設備並有不同的設置的滾動應該如何看起來和表現 – LGSon
哇,非常感謝!我認爲這實際上是不可能的,現在我不必爲執行jQuery而煩惱。 – Krys