0

I'm trying to create a tool/navbar that doesn't move, and with content filling the rest of the screen but that cannot overflow into the toolbar (which is the current behavior). So the content class should only allow the stack to overflow (no pun there at all) in the downward direction. Google get's confused with the keywords necessary to describe the issue. Eventually I want to add a pop-up side bar menu as well, but I suppose that's just a matter of enclosing all the current code in a div and sliding that around when the side bar button is clicked. Here's the code:

.container{
height: 95vh;
width: 100vw;
max-width: 100%;
display:flex;
flex-direction: column;
justify-content:center;
align-items: center;
margin: 0px;}

.content {
    display: flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    flex-grow: 1;
  }

 .toolbar {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 60px;
flex-shrink: 0;
display: flex;
align-items: center;
background-color:maroon;

}

Here's the html:

<div class="toolbar" role="banner">
<img src='sidebar_button.jpg'>
<span>Home</span>
</div>
  <div class="container">

  <div class="content">
    <!-- Resources -->
</div>
</div>
1
  • I may be misunderstanding your question, but couldn't you just give your content a lower z-index to push it behind the top-bar, and give your top-bar a position: fixed? Commented Jul 22, 2021 at 13:46

1 Answer 1

0

Provided I correctly understand what you are asking for - a header with that does not move when scrolled, and content below it that will scroll but will not appear over the top-bar - the solution is pretty simple.

Really, you just need to give your top-bar a position: fixed. That keeps it from scrolling and creates a new "stacking context" for that meaning that it is, by default, displaying on top of everything else. I have created a little demo to showcase this below.

body {
  height: 200vh;
  margin: 0;
  font-family: "Segoe UI Variable Text", system-ui, ui-rounded, sans-serif;
}
.topbar {
  background-color: #8CB0C8;
  position: fixed;
  width: 100vw;
  height: 64px;
  top: 0;
  left: 0;
  display: grid;
  align-content: center;
  box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.16);
}
h1 {
  margin: 0;
  font-family: "Segoe UI Variable Display", system-ui, ui-rounded, sans-serif;
  font-weight: 500;
}
.content {
  width: 100%;
  max-width: 1080px;
  margin: 72px auto 0;
}
<div class="topbar">
  <h1 class="icon">🧔</h1>
</div>
<div class="content">
  <h1>This is your content</h1>
  <p>This is a whole lot of content...</p>
</div>

4
  • 1
    Wow, thanks so much Calvin! So what I was referring to was when flex is used, it will attempt to stabilize the content when the electron window is resized. Unfortunately it keeps moving upward, under the toolbar. I'd like it to overflow, but not to overflow upward, as this makes the text difficult to see. As I'm using flex, the scrollbar doesn't appear (and I don't really want to it, it's a desktop app). I'm hoping the text just becomes overflows off the bottom of the screen, without being blocked by the toolbar. Commented Jul 22, 2021 at 14:46
  • I understand - I'll take another swing at this in a few minutes. Commented Jul 22, 2021 at 15:14
  • Have you taken a look at this post? Commented Jul 22, 2021 at 15:34
  • Hey there! Thanks so much. It's not exactly what I was looking for but it's in the right direction, and I can emulate the behavior by limiting the minimum screen height/width. Thanks! Commented Jul 23, 2021 at 15:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.