In my next.js project, I have developed a Container component with specific styles. As I incorporate this container component throughout the site, I aim to assign it a className for context-based styling.
Illustrated below is an example of the Container component:
const Container = (props) => (
<>
<div className="container">
{props.children}
</div>
<style jsx>{`
.container{
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
`}</style>
</>
)
export default Container;
The Container has been successfully styled to have a maximum width of 1200px and centered using auto margins. All functioning as intended.
I am now considering utilizing this component in the header section of my website. In the case of the header, I wish for the Container component to behave as a flexbox:
import Container from './Container'
const Header = (props) => (
<>
<header>
<Container className="header-col">
<div>
<h1>{props.title}</h1>
</div>
<nav>
<ul>
{/* Navigation items */}
</ul>
</nav>
</Container>
</header>
<style jsx>{`
.header-col{
display: flex;
justify-content: space-between;
}
`}</style>
</>
)
export default Header;
Upon reviewing the site, I observed that the flexbox style set for the Container component within the header is not being applied.
I anticipated the className to trigger additional styles, but it seems to treat it as a prop rather than a class name. However, I prefer maintaining code reusability by implementing style inheritance on components.
Is there a way to achieve this?
Appreciate any guidance provided!