Brady W Brady W - 4 months ago 7
CSS Question

HTML/CSS Div won't scroll when zoomed in

I have a sidebar on my webpage that contains a paragraph and 4 buttons. When I zoom into my webpage I want a scrollbar to appear to scroll through all of them, but it is not appearing.

Here is my code:

HTML




<title>Calendar</title>
<link rel = "stylesheet" type = "text/css" href = "calendarstyle.css" />

</head>

<script src = "calendarapp.js"></script>

<body>

<div id = "sidebar">
<div id = "viewmode">
<p id = "viewlabel">View Mode</p>
<button class = "viewbutton" id = "yearbutton">Year</button>
<button class = "viewbutton" id = "monthbutton">Month</button>
<button class = "viewbutton" id = "weekbutton">Week</button>
<button class = "viewbutton" id = "daybutton">Day</button>
</div>
</div>

</body>
</html>


CSS

* {
margin: 0px;
padding: 0px;
font-family: Monospace;
}

#sidebar {
background-color: rgb(243, 243, 243);
height: 100%;
width: 20%;
position: fixed;
}

#viewmode {
position: absolute;
width: 100%;
}

#container {
width: 100%;
height: 100px;
top: 0px;
left: 0px;
position: absolute;
overflow-y: scroll;
}

#viewlabel {
margin-top: 5px;
font-size: 20px;
text-align: center;
font-weight: bold;
color: rgb(200, 200, 200);
}

.viewbutton {
display: block;
width: calc(100% - 10px);
margin: 5px;
background-color: rgb(200, 200, 200);
color: white;
padding: 3px;
outline: none;
border: none;
font-size: 17px;
transition-duration: 0.2s;
}

.viewbutton:hover {
background-color: rgb(106, 234, 116);
}


I have been trying to use a "container" div, but nothing is working for me

Answer
add `overflow-y:auto;` to sidebar class it will work

* {
    margin: 0px;
    padding: 0px;
    font-family: Monospace;
}

#sidebar {
    background-color: rgb(243, 243, 243);
    height: 100%;
    width: 20%;
    position: fixed;
    overflow-y:auto;
  
}

#viewmode {
    position: absolute;
    width: 100%;
}

#container {
    width: 100%;
    height: 100px;
    top: 0px;
    left: 0px;
    position: absolute;
    overflow-y: scroll;
}

#viewlabel {
    margin-top: 5px;
    font-size: 20px;
    text-align: center;
    font-weight: bold;
    color: rgb(200, 200, 200);
}

.viewbutton {
    display: block;
    width: calc(100% - 10px);
    margin: 5px;
    background-color: rgb(200, 200, 200);
    color: white;
    padding: 3px;
    outline: none;
    border: none;
    font-size: 17px;
    transition-duration: 0.2s;
}

.viewbutton:hover {
    background-color: rgb(106, 234, 116);
}
<title>Calendar</title>
<link rel = "stylesheet" type = "text/css" href = "calendarstyle.css" />

</head>

<script src = "calendarapp.js"></script>

<body>

<div id = "sidebar">
    <div id = "viewmode">
        <p id = "viewlabel">View Mode</p>
        <button class = "viewbutton" id = "yearbutton">Year</button>
        <button class = "viewbutton" id = "monthbutton">Month</button>
        <button class = "viewbutton" id = "weekbutton">Week</button>
        <button class = "viewbutton" id = "daybutton">Day</button>
    </div>
</div>

</body>
</html>

Comments