Reputation: 1
menu links get out of the window area? Why does it happen? Why can't I scroll up to the first menu on mobile screens? What's wrong with my code?
Here I want to make a fullscreen popup menu, that is why .menu is fixed, and I want to center all links as well. But I can't seem to get some menu links on smaller devices. How can I leave .menu fixed and center all links?
.menu {
position: fixed;
width: 100%;
height: 100%;
/* background: #05b5f9; */
top: 0;
left: 0;
}
.list {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
padding: 30px;
align-items: stretch;
text-align: center;
/* position: relative; */
overflow: auto;
}
.list li {
list-style: none;
margin: 5px;
}
.link {
display: block;
padding: 20px;
text-decoration: none;
border: 1px solid #05b5f9;
font-size: 20px;
color: #05b5f9;
font-weight: 700;
}
<div class="menu">
<ul class="list">
<li><a href="" class="link">Menu1</a></li>
<li><a href="" class="link">Menu2</a></li>
<li><a href="" class="link">Menu3</a></li>
<li><a href="" class="link">Menu4</a></li>
<li><a href="" class="link">Menu5</a></li>
<li><a href="" class="link">Menu6</a></li>
<li><a href="" class="link">Menu7</a></li>
<li><a href="" class="link">Menu8</a></li>
</ul>
</div>
Upvotes: 0
Views: 66
Reputation: 33
The problem I see is in your .menu
class. Since the menu class element goes inside the document element, the height: 100%;
will take the height of the parent, i.e. the document, i.e. the entire viewport height.
I don't see any problem while running your code in a separate window. This is what I see while running your code in full screen. I am guessing that the problem arises when you have something displaying over the menu element, because the top: 0;
will make sure the the menu element starts from the top of the screen.
If you can share the full code, maybe we can help better. Cheerio!
Upvotes: 1
Reputation: 384
You set a fixed height for your .menu
which in combination with display: fixed
won't let you scroll.
.menu {
width: 100%;
/* background: #05b5f9; */
top: 0;
left: 0;
}
.list {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
padding: 30px;
align-items: stretch;
text-align: center;
/* position: relative; */
overflow: auto;
}
.list li {
list-style: none;
margin: 5px;
}
.link {
display: block;
padding: 20px;
text-decoration: none;
border: 1px solid #05b5f9;
font-size: 20px;
color: #05b5f9;
font-weight: 700;
}
<div class="menu">
<ul class="list">
<li><a href="" class="link">Menu1</a></li>
<li><a href="" class="link">Menu2</a></li>
<li><a href="" class="link">Menu3</a></li>
<li><a href="" class="link">Menu4</a></li>
<li><a href="" class="link">Menu5</a></li>
<li><a href="" class="link">Menu6</a></li>
<li><a href="" class="link">Menu7</a></li>
<li><a href="" class="link">Menu8</a></li>
</ul>
</div>
That you are currently just able to scroll a little bit is the result of overflow: auto;
on your .list
Upvotes: 1