Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

css - Element "tucked" under another element...and it shouldn't

This should be a CSS style question, but it has some C#/Blazor components...that's why I tagged both.

Here my main layout:

<div class="container-fluid p-0 d-flex flex-column min-vh-100">
  <div class="navbar fixed-top">This is the header</div>
  <div class="content flex-grow-1">
    @Body
  </div>
  <div class="navbar tiny-text fixed-bottom d-flex justify-content-center">
  <div id="footer_div">This is the footer</div>
</div>

My problem is that whatever component that I have that takes place in @Body will appear "under" the header bar (even it's just a simple div or span). My workaround right now is use css' top to avoid the header. What do I have to do, so that the elements in the div won't start from underneath the header element?

Thanks!

question from:https://stackoverflow.com/questions/66064088/element-tucked-under-another-element-and-it-shouldnt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you remove the fixed-top from your navbar element the body will no longer "tuck" under the header.

<div class="container-fluid p-0 d-flex flex-column min-vh-100">
  <div class="navbar">This is the header</div>
  <div class="content flex-grow-1">
    @Body
  </div>
  <div class="navbar tiny-text fixed-bottom d-flex justify-content-center">
    <div id="footer_div">This is the footer</div>
  </div>
</div>

If you want to retain the fixed-like header and footer you should be able to use something like the below adapted from this answer

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.content {
  overflow: auto;
}
<header class="navbar">This is the header</header>
<main class="content flex-grow-1">
  @Body
</main>
<footer class="navbar tiny-text d-flex justify-content-center">
  <section>This is the footer</section>
</footer>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...