#parent{width: 100%;height: 100%;overflow: hidden;}
#child{width: 100%;height: 100%;overflow-y: scroll;padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */box-sizing: content-box; /* So the width will be 100% + 17px */}
<div id="maincontainer" ><div id="child">this is the 1st step</div><div id="child">this is the 2nd step</div><div id="child">this is the 3rd step</div>
function reloadScrollBars() {document.documentElement.style.overflow = 'auto'; // Firefox, Chromedocument.body.scroll = "yes"; // Internet Explorer only}
function unloadScrollBars() {document.documentElement.style.overflow = 'hidden'; // firefox, chromedocument.body.scroll = "no"; // Internet Explorer only}
<div class="outer-container"><div class="inner-container"><div class="element">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. Nulla vitae turpis utdui 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 tristiquealiquam rutrum. 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, molestievel justo. 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.</div></div></div>
html {overflow: scroll;overflow-x: hidden;}::-webkit-scrollbar {width: 0; /* Remove scrollbar space */background: transparent; /* Optional: just make scrollbar invisible */}/* Optional: show position indicator in red */::-webkit-scrollbar-thumb {background: #FF0000;}
.overflow-x-scroll-no-scrollbar {overflow: hidden;}.overflow-x-scroll-no-scrollbar div {overflow-x: hidden;margin-bottom: -17px;overflow-y: hidden;width: 100%;}.overflow-x-scroll-no-scrollbar div * {overflow-x: auto;width: 100%;padding-bottom: 17px;white-space: nowrap;cursor: pointer}
/* The following classes are only here to make the example looks nicer */.row {width: 100%}.col-xs-4 {width: 33%;float: left}.col-xs-3 {width:25%;float:left}.bg-gray {background-color: #DDDDDD}.bg-orange {background-color:#FF9966}.bg-blue {background-color: #6699FF}.bg-orange-light{background-color: #FFAA88}.bg-blue-light{background-color: #88AAFF}
<html><body><div class="row"><div class="col-xs-4 bg-orange">Column 1</div><div class="col-xs-3 bg-gray">Column 2</div><div class="col-xs-4 bg-blue">Column 3</div></div><div class="row"><div class="col-xs-4 bg-orange-light">Content 1</div><div class="col-xs-3 overflow-x-scroll-no-scrollbar"><div><div>This content too long for the container, so it needs to be hidden but scrollable without scrollbars</div></div></div><div class="col-xs-4 bg-blue-light">Content 3</div></div></body></html>
懒惰的人的简短版本:
.overflow-x-scroll-no-scrollbar {overflow: hidden;}.overflow-x-scroll-no-scrollbar div {overflow-x: hidden;margin-bottom: -17px;overflow-y: hidden;width: 100%;}.overflow-x-scroll-no-scrollbar div * {overflow-x: auto;width: 100%;padding-bottom: 17px;white-space: nowrap;cursor:pointer}
/* The following classes are only here to make the example looks nicer */.parent-style {width: 100px;background-color: #FF9966}
<div class="parent-style overflow-x-scroll-no-scrollbar"><div><div>This content too long for the container, so it needs to be hidden but scrollable without scrollbars</div></div></div>
// Content is the element you want to apply the wheel scroll effect tocontent.addEventListener('wheel', function(e) {const step = 100; // How many pixels to scroll
if (e.deltaY > 0) // Scroll downcontent.scrollTop += step;else // Scroll upcontent.scrollTop -= step;});
<div id="container"><div id="content">My content that could overflow horizontally</div><div id="scroll-cover"> </div></div>
对应的CSS如下:
#container{width: 100%;height: 100%;overflow: hidden;position: relative;}
#content{width: 100%;height: 100%;overflow-x: scroll;}#scroll-cover{width: 100%;height: 20px;position: absolute;bottom: 0;background-color: #fff; /*change this to match color of page*/}
function detectMouseWheelDirection(e) {var delta = null, direction = false;if (!e) { // If the event is not provided, we get it from the window objecte = window.event;}if (e.wheelDelta) { // Will work in most casesdelta = e.wheelDelta / 60;} else if (e.detail) { // Fallback for Firefoxdelta = -e.detail / 2;}if (delta !== null) {direction = delta > 0 ? -200 : 200;}return direction;}
if (element.addEventListener) {element.addEventListener('DOMMouseScroll', function(e) {element.scrollBy({top: detectMouseWheelDirection(e),left: 0,behavior: 'smooth'});});}
/* Hide HTML and body scroll bar in CSS grid context */html, body {position: static; /* Or relative or fixed ... */box-sizing: content-box; /* Important for hidding scrollbar */display: grid; /* For CSS grid */
/* Full screen */width: 100vw;min-width: 100vw;max-width: 100vw;height: 100vh;min-height: 100vh;max-height: 100vh;margin: 0;padding: 0;}
html {-ms-overflow-style: none; /* Internet Explorer 10+ */overflow: -moz-scrollbars-none; /* Should hide the scroll bar */}
/* No scroll bar for Safari and Chrome */html::-webkit-scrollbar,body::-webkit-scrollbar {display: none; /* Might be enough */background: transparent;visibility: hidden;width: 0px;}
/* Firefox only workaround */@-moz-document url-prefix() {/* Make HTML with overflow hidden */html {overflow: hidden;}
/* Make body max height auto *//* Set right scroll bar out the screen */body {/* Enable scrolling content */max-height: auto;
/* 100vw +15px: trick to set the scroll bar out the screen */width: calc(100vw + 15px);min-width: calc(100vw + 15px);max-width: calc(100vw + 15px);
/* Set back the content inside the screen */padding-right: 15px;}}
body {/* Allow vertical scroll */overflow-y: scroll;}
<div id="container1"><div id="container2"><pre>
Select from left and drag to right to scroll this very long sentence. This should not show scroll bar at bottom or on the side. Keep scrolling .......... ............ .......... ........... This Fiddle demonstrates that scrollbar can be hidden. ..... ..... ..... .....</pre>
</div><div>
<div class="barrel"><div class="clipper"><p class="clippercontent">Lorem</p></div><div id='navcontainer'><p class="navcontent" >I want to be able to scroll through the whole page, but without the scrollbar being shown. Is there a way I can remove the scrollbar while still being able to scroll the whole page? With just CSS or HTML, please.</p></div></div>
原理:#导航容器将容纳我们的.导航内容,并具有滚动条。.桶将隐藏#导航容器的滚动条。
css:
.barrel{border: 0.8px solid #110011;position: relative;overflow: hidden;}.barrel #navcontainer{overflow: scroll; overflow-y: hidden;position: absolute;/* absolute positioned contents will not affect their parents */top: 0; left: 0; right: 0;white-space: nowrap;}/* style .clipper and .clippercontent, as a structural-image of #navcontainer and .navcontent respectively This will help .barrel have the same height as the #navcontainer */.barrel .clipper{overflow: hidden;width: 0px;white-space: nowrap;}.navcontent, .clippercontent{padding: 3px 1px;}
div {-ms-overflow-style: none; /* Edge, Internet Explorer */scrollbar-width: none; /* Firefox */overflow-y: scroll;}
// hides scrollbars while allowing to scrolldiv::-webkit-scrollbar {display: none; /* Chrome, Safari, Opera */}