Hi, I have a simple grid layout with a header, main content, and footer. Occasionally, the main content includes a blog post, and I’d like to have a table of contents appear in an aside to the right of the blog post on desktop PCs. However, on mobile devices, I want the table of contents to appear below the blog post title. How can I achieve this with CSS and HTML? I want the aside area to switch between two positions: once appearing as a sidebar and once being part of the main content.
The page looks like this:
<body>
<div class="grid-container">
<header>
Header
</header>
<main class="main">
<div class="blog-container">
<div class="blog-post">
<h2>Title</h2>
<p>Lorem ipsum dolor sit..</p>
</div>
</div>
</main>
<footer class="footer">
Footer
</footer>
</div>
</body>
The mobile first CSS:
.grid-container {
display: grid;
grid-gap: 10px;
grid-template-areas:
"header"
"main"
"footer"
}
The desktop CSS:
@media (min-width: 52em) {
.grid-container {
grid-template-columns: minmax(300px, 800px);
justify-content: center;
}
}
I’m curious if it’s possible to achieve what I want using only CSS and media queries. Any suggestions appreciated.