2017-06-21 50 views
1

我创建了一个例子滚动在侧面板上有更多的锚标签。不能完全倒在侧面板中的HTML示例从w3school

为什么滚动到左侧窗格的底部是不可能的?

在某些情况下,当您使用栏或鼠标滚轮向下滚动时,发现该行为存在差异,因此请尝试两者。我尝试了Chrome和Firefox。

HTML:

<div id="mySidenav" class="sidenav"> 
    <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a> 
    <a href="#">About</a> 
    <a href="#">Services</a> 
    <a href="#">Clients</a> 
    <a href="#">Contact</a> 
    <a>A</a> 
    <a>B</a> 
    <a>C</a> 
    <a>D</a> 
    <a>E</a> 
    <a>F</a> 
    <a>G</a> 
    <a>H</a> 
    <a>I</a> 
    <a>J</a> 
    <a>K</a> 
    <a>L</a> 
    <a>M</a> 
    <a>N</a> 
    <a>O</a> 
    <a>P</a> 
    <a>Q</a> 
    <a>R</a> 
    <a>S</a> 
    <a>T</a> 
    <a>U</a> 
    <a>V</a> 
    <a>..</a> 
    <a>W</a> 
    <a>X</a> 
    <a>Y</a> 
    <a>Z</a> 
</div> 

<div id="main"> 
    <h2>Sidenav Push Example</h2> 
    <p>Click on the element below to open the side navigation menu, and push this content to the right.</p> 
    <span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; open</span> 
</div> 

<script> 
function openNav() { 
    document.getElementById("mySidenav").style.width = "250px"; 
    document.getElementById("main").style.marginLeft = "250px"; 
} 

function closeNav() { 
    document.getElementById("mySidenav").style.width = "0"; 
    document.getElementById("main").style.marginLeft= "0"; 
} 
</script> 

</body> 

CSS:

body { 
    font-family: "Lato", sans-serif; 
} 

.sidenav { 
    height: 100%; 
    width: 0; 
    position: fixed; 
    z-index: 1; 
    top: 0; 
    left: 0; 
    background-color: #111; 
    overflow-x: hidden; 
    transition: 0.5s; 
    padding-top: 60px; 
} 

.sidenav a { 
    padding: 8px 8px 8px 32px; 
    text-decoration: none; 
    font-size: 25px; 
    color: #818181; 
    display: block; 
    transition: 0.3s; 
} 

.sidenav a:hover, .offcanvas a:focus{ 
    color: #f1f1f1; 
} 

.sidenav .closebtn { 
    position: absolute; 
    top: 0; 
    right: 25px; 
    font-size: 36px; 
    margin-left: 50px; 
} 

#main { 
    transition: margin-left .5s; 
    padding: 16px; 
} 

@media screen and (max-height: 450px) { 
    .sidenav {padding-top: 15px;} 
    .sidenav a {font-size: 18px;} 
} 

回答

1

添加到您的CSS。

.sideNav { 
    overflow: auto; 
} 

这应该做到这一点。

1

该问题与填充顶部有关。消除它将使整个内容得以显示。

下面是一个例子https://jsfiddle.net/kzpjmmf2/

.sidenav { 
    height: 100%; 
    width: 0; 
    position: fixed; 
    z-index: 1; 
    top: 0; 
    left: 0; 
    background-color: #111; 
    overflow-x: hidden; 
    transition: 0.5s; 
} 
-1

你只需要减少填充

.sidenav { 
    height: 100%; 
    width: 0; 
    position: fixed; 
    z-index: 1; 
    top: 0; 
    left: 0; 
    background-color: #111; 
    overflow-x: hidden; 
    transition: 0.5s; 
    padding-top: 10px; 
} 

这里工作的例子

https://codepen.io/anon/pen/EXXaKN