I am designing a page where on top i have a fixed navbar and under that I will have a <main>
block. Inside <main>
I have mutiple sections.
From Navbar when I click on any link to jump to the specific section the section heading slides under the navbar.
I have tried adding margin-top for both <main>
and <section>
but still the issue persist.
html, body{
margin:0;
padding:0;
scroll-behavior: smooth;
}
.nav{
height: 4rem;
width:100%;
background: transparent;/* #889EAF; */
border: 2px solid black;
position: fixed;
display: flex;
flex-direction: row;
justify-content: space-around;
}
main{
margin-top:4rem;
}
section {
display: flex;
/* margin-top:4rem; */
/* justify-content: center; */
align-items: center;
flex-direction: column;
height: 93vh;
/* margin-top:7vh; */
}
.about {
height:100vh;
background:#D4B499;
}
.more {
height:fit-content;
background: #F3D5C0;
}
.card{
display: flex;
flex-direction: column;
/* position: absolute; */
/* top: 13%; */
align-items: center;
background-color: white;
padding: 0.75rem;
width: 90%;
height: fit-content;
border: 1px solid #bfc5c9;
border-radius: 1.125rem;
box-shadow: 0px 0px 20px #bdc3c7;
/* z-index: 10; */
margin: 1rem;
}
.heading {
align-self: center;
font-size: 2.5rem;
padding: 1rem 0rem 0rem 2rem;
}
<div class="nav">
<div><a href="#about">About</a></div>
<div><a href="#more">More</a>
</div>
</div>
<main>
<section id="about" class="about">
<div class="heading">This is about section</div>
<div class="card">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
</section>
<section id="more" class="more">
<div class="heading">This is something more</div>
<div class="card">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div class="card">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div class="card">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div class="card">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</section>
</main>
Please find a live example of the issue @ CodePen