简体   繁体   English

如何在 html 侧菜单中添加滚动条

[英]How to add a scroll bar to html side menu

How would I add a scroll bar that is solely for the left side navigation menu?如何添加仅用于左侧导航菜单的滚动条? I have tried adding overflow-y: scroll;我尝试添加溢出-y:滚动; in various locations but that has not seemed to work.在不同的地方,但这似乎没有奏效。 I am somewhat of a novice/newbie at web design so I have sort of hacked together various tips from guides and templates.我在 web 设计方面有点新手/新手,所以我从指南和模板中整理了各种技巧。 Any tips would be much appreciated.任何提示将不胜感激。 Thanks!谢谢!

<ul class="navigation">
        <li class="nav-item"><input type="type" placeholder="Search for a country..." name="search" id="search"> </form> </li>
        <li class="nav-item"><a href="#">Home</a></li>

    </ul>
    <input type="checkbox" id="nav-trigger" class="nav-trigger"/>
    <label for="nav-trigger"></label>
    <div class="site-wrap">

And here's some of my css这是我的一些 css

.navigation {
    position: fixed;
    background-color: rgb(230, 239, 252); 
    text-align: left;
    list-style: none;
    width: 100%;
    height: 10px;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 0;
}

/* Navigation Menu - List items */
.nav-item {
    /* non-critical appearance styles */
    width: 200px;
    border-top: 1px solid #111;
    border-bottom: 1px solid #000;
    font-family:'Helvetica', 'Arial', 'Sans-Serif';
}

.nav-item a {
    /* non-critical appearance styles */
    display: block;
    padding: 1em;
    background: linear-gradient(135deg, rgba(216, 214, 214, 0) 0%,rgba(230, 229, 229, 0.65) 100%);
    color: rgb(8, 8, 8);
    font-size: 1.2em;
    text-decoration: none;
    transition: color 0.2s, background 0.5s;
}

.nav-item a:hover {
    color: #333;
    background: linear-gradient(135deg, rgba(0,0,0,0) 0%,rgba(12, 52, 126, 0.65) 100%);
}

.site-wrap {
    min-width: 100%;
    min-height: 100%;
    background-color: rgb(230, 239, 252);
    position: relative;
    top: 0;
    bottom: 100%;
    left: 0;
    z-index: 1;
    padding: 4em;
}

.nav-trigger {
    position: absolute;
    clip: rect(0, 0, 0, 0);
}

label[for="nav-trigger"] {
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 2;    
    width: 30px;
    height: 30px;
    cursor: pointer;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' x='0px' y='0px' width='30px' height='30px' viewBox='0 0 30 30' enable-background='new 0 0 30 30' xml:space='preserve'><rect width='30' height='6'/><rect y='24' width='30' height='6'/><rect y='12' width='30' height='6'/></svg>");
    background-size: contain;
}

.nav-trigger + label, .site-wrap {
    transition: left 0.2s;
}

.nav-trigger:checked + label {
    left: 215px;
}

.nav-trigger:checked ~ .site-wrap {
    left: 200px;
}

body {
    overflow-x: hidden;
}

let me know if you need to see more code snippets.如果您需要查看更多代码片段,请告诉我。

You can add this class to your css:您可以将此 class 添加到您的 css:

div.scroll { 
                margin:4px, 4px; 
                padding:4px; 
                background-color: green; 
                width: 500px; 
                height: 110px; 
                overflow-x: hidden; 
                overflow-x: auto; 
                text-align:justify; 
            }

And place your side menu into a div like this:并将您的侧边菜单放入这样的 div 中:

<div class="scroll">Your side menu here...</div>

You can also check the following link for more info: https://www.geeksforgeeks.org/making-a-div-vertically-scrollable-using-css/您还可以查看以下链接以获取更多信息: https://www.geeksforgeeks.org/making-a-div-vertically-scrollable-using-css/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM