Reputation: 316
I have this navbar component that sits above my hero section. My problem is if I make the background transparent, it will just be white instead of being on top of my hero image.
Here is the code for the navbar
export const Nav = styled.nav`
background: transparent;
height: 80px;
display: flex;
justify-content: space-between;
padding: 0.5rem calc((100vw - 1000px) / 2);
z-index: 10;
`;
In my App.js the navbar just stacks on top of the hero section
function App() {
return (
<Router>
<Navbar />
<Hero />
</Router>
);
}
So no matter what it will always be located on top.
The only alternative I've found is to add
margin-top: -80px
to my hero section, but I feel like there's a better way to do it.
The negative margin essentially does the trick, and you can see the navbar is over the hero image, but now I lose -80px of the hero section and it doesn't display the full 100% of it.
Any ideas of how to create a navbar that is located on top of a hero section without using negative margins?
Upvotes: 1
Views: 1998
Reputation: 11
Try this.
At your Hero section keep margin-top: -80px
and instead of height: 100%
put height: 100vh
; Tell me if it helped
Upvotes: 1