The intricate design of a CSS grid within another CSS

I'm currently tackling a CSS grid project where I am aiming to have two divs within a container each occupy 50% of the width. However, I am facing some challenges in achieving this.

Within the nav element, I have two divs that I want to span across 50% of the container width each by utilizing the grid layout syntax. How would you go about implementing this?

Code:

$gutter: 30px;
$columns: 12;
$maxwidth: 1200px;

#container {
    max-width: $maxwidth;
    width: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat($columns, 1fr);
    grid-column-gap: $gutter;
    grid-template-areas: "nav" "header" "main" "footer";
}

   header, nav, main, footer {
       grid-column: span $columns;
   }

Markup:

<div id="container">
    <nav>
        <div></div>
        <div></div>
    </nav
    <header></header>
    <main></main>
    <footer></footer>
</div>

image: https://i.sstatic.net/bHJ0H.png

Answer №1

Here is a simple way to achieve this:

nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

nav div {
  background: red;
  height: 250px;
}

nav div + div {
  background: green;
}
<div id="container">
    <nav>
        <div></div>
        <div></div>
    </nav>
    <header></header>
    <main></main>
    <footer></footer>
</div>

Explore more about CSS Grid

Answer №2

header {
    display: flex;
    justify-content: space-between;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Changing the CSS property from "display: none" to "display: block" using JavaScript causes all the div elements to overlap

My issue involves several radio inputs where clicking one should reveal a hidden div containing information. However, when this div appears, it overlaps with the footer instead of staying positioned between the footer and radio input as intended. I am str ...

The collapsible navigation bar in Bootstrap

I'm having issues with my Bootstrap collapsible menu. Can someone help me identify the problem? <nav class="navbar navbar-default navbar-fixed-top"> <div class="container-fluid"> <div class="navbar-header"> <a class= ...

Stable element placement in relation to its container

While dragging an element, it obtains a position: fixed. This particular element is located within a modal that is directly nested inside the body element. In the image below, the modal appears in gray, while the rest of the body is black, and the button ...

Issues following compilation with npm run prod

I am currently working on a small website using Laravel and Tailwind CSS on shared hosting. While I am able to use a command line tool on the host, I have encountered an issue. In my local environment, Tailwind works perfectly fine. However, after running ...

When navigating back, the Bootstrap Multistep Form breaks down

Tools I'm currently utilizing: HTML, CSS, Javascript, Bootstrap 3 Library / Package in use: https://codepen.io/designify-me/pen/qrJWpG Hello there! I am attempting to customize a Codepen-based Bootstrap Multistep Form from the provided link abov ...

Applying media queries to incorrect screen sizes

My media query seems to be behaving oddly. @media only screen and (max-width: 1200px) { .tool-panel { margin: 0px 24px 0px 0px; } } It is getting applied at 1183.20px instead of 1200px. This discrepancy is consistent across all browsers ev ...

Why does Javascript Tic-Tac-Toe delay notifying the user until the entire board is full?

There have been a lot of questions about Tic-Tac-Toe javascript, but my issue is unique. My code works fine, but it doesn't declare a winner or a tie game until the entire board is filled. I suspect that my if statements are causing problems and can&a ...

Strategies for Updating Backgrounds on Individual WordPress Pages

I am looking to revamp a WordPress blog with 5 different pages, each requiring a unique background image. Is there a method to achieve this without altering the background element, but instead changing the background image of the #main element in my CSS? ...

Category-Specific Page Display

Can anyone help with CSS coding using Wordpress Elementor to make a page only display posts from the coaching category? I attempted to use this selector article.type-post:not(.category-coaching) { display: none; }, but it doesn't seem to be functi ...

Guide on altering the cell's background hue depending on its value through javascript

I'm dealing with a table that has 3 columns: field1 is a Category field2 and field3 contain Measures (specifically integers 1, 2, 3, 4, and 5). Is there a way to use Javascript to conditionally format the background color of cells in the table hol ...

Styling a GWT StackPanel for a Unique Look

I'm facing some difficulty with styling a stackpanel in my app. I've tried different methods, but none seem to work as expected. The first method involves applying CSS directly to the stackpanel elements: .gwt-StackPanel .gwt-StackPanelItem { ...

Organizing Content with CSS/Bootstrap Grid Row Alignment

I'm struggling to figure out why there is extra space above the nested grid row. I want to center align it, similar to how you would do in Excel. Any suggestions on how to achieve this? My layout includes a fluid container with a nested grid row cons ...

What is the best way to create a fixed navigation bar that only stays fixed on particular sections of my website?

In my digital portfolio, I have divided it into "4 sections," each represented by a separate scrollable web page. These sections are also known as parts, starting from #part1 up to 4. For section 1 (#part1), I prefer not to display the navigation bar. How ...

Arrow icon indicating active status in side navigation bar

As part of my journey to enhance my Html and Css skills, I have been recreating templates from various websites. While this exercise has taught me a lot, I have hit a roadblock with one particular template. I am struggling to understand how they manage to ...

Having trouble locating the nivoslider IE8 jQuery bug, can't seem to track it

I am encountering an issue with the nivoslider script in IE8 and I am having trouble identifying what is causing it. The nivoslider works perfectly fine in all other browsers except for IE8. Any help or guidance on this matter would be greatly appreciated ...

Half of the sections will not stack on mobile devices

UPDATE I found and fixed a typo in the code, making adjustments to both the JSFiddle and this post to show the correction. The Headline is supposed to take up 100% height but currently isn't. Still seeking feedback on this issue. Everything looks per ...

Sliding Up Transition Effect for Footer with JQuery or CSS3

I am attempting to replicate a sleek slide up footer that caught my eye on The Internship Movie Site. I have created the wireframe layout, but I am struggling to figure out the correct CSS transition effect. Although I have experimented with the "top" and ...

Display <div> exclusively when in @media print mode or when the user presses Ctrl+P

Looking for a way to create an HTML division using the div element that is only visible when the print function is used (Ctrl+P) and not visible in the regular page view. Unfortunately, I attempted the following method without success. Any advice or solut ...

CSS error: Menu hover glitch concealed

I'm currently facing an issue with the navigation on my website. Whenever I place a logo image above the menu, the hover effect of the menu stops working correctly. To clarify: the background doesn't change on hover, but the border does. Here are ...

How can JQuery and CSS brighten up buttons?

Is there a way for me to create an "enlightening" effect similar to the one seen in the "Tags" section on this website? I am not just looking to change the color of the background from gray to white, but instead, I want to progressively make the button li ...