How can I make a grandchild element span 100% width within CSS Grid?

Is it possible to extend one of the grandchild elements to 100% width in CSS Grid while the parent container is divided into 3 fractions?

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.container > div {
  background-color: #4834d4;
  width: 100%;
}
.container > div .child_01 {
  background-color: #f9ca24;
  width: 80%;
  height: 50px;
  margin: 1rem auto;
}
.container > div .child_02 {
  background-color: #eb4d4b;
  width: 80%;
  height: 50px;
  margin: 1rem auto;
}
<div class="container">
<div>
<div class="child_01"></div>
<div class="child_02"></div>
</div>
<div>
<div class="child_01"></div>
<div class="child_02"></div>
</div>
<div>
<div class="child_01"></div>
<div class="child_02"></div>
</div>
</div>

My goal is to achieve a layout similar to this: desired layout

Would it be feasible to accomplish this using CSS Grid?

Answer №1

Behold, here is the solution:

.container {
  padding: 20px;
  display: flex;
  flex-direction: column;
  background-color: #4834d4;
}

.container > div {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.child_01 {
  display: inline-flex;
  background-color: #f9ca24;
  width: 30%;
  height: 50px;
}

.child_02 {
  display: flex;
  background-color: #eb4d4b;
  width: 100%;
  height: 50px;
  margin: 1rem auto;
}
<div class="container">
  <div>
    <div class="child_01"></div>
    <div class="child_01"></div>
    <div class="child_01"></div>
   </div>
   <div class="child_02"></div>
  <div class="child_02"></div>
  <div class="child_02"></div>
</div>

I opted for using flex over grid in this scenario.

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

What is the best way to eliminate an unknown border within a string builder table?

My code is generating a PDF and I am encountering an issue with a black bordered cell appearing behind the image in this specific line: sb.AppendLine("<tr><td>" + "~/images/Products/" + imageName + "</td><td>~/images/spacer.gif< ...

Hide the navigation menu when a page link is selected

Within my Angular 8 application, a fixed navigation bar is positioned at the top of the screen. Upon hovering over a dropdown nav link, a menu will appear for the user to explore. However, when a user clicks on one of these menu links, Angular Routing is ...

Within the HTMLDivElement.drop, the parent element now encapsulates the new child element

I've encountered a DOM exception that has me stuck. My issue involves div elements and a button - when the user clicks the button, a random div is selected and another div with a background-color class is appended to it. Essentially, clicking the butt ...

Error encountered in Django when attempting to pass an SQL query due to an UnboundLocalError

When I encountered an issue: Environment: Request Method: POST Request URL: http://127.0.0.1:8000/mainpage.html Django Version: 3.2.12 Python Version: 3.7.4 Installed Applications: ['django.contrib.admin', 'django.contrib.auth' ...

When the child element's "aria-expanded" attribute is set to true, a CSS class should be dynamically

Is there a way to apply a grey background to the first div when the dropdown is open? I've managed to add CSS based on the child elements' aria-expanding attribute, but I'm unsure how to do it for a parent element. Since I am using Vue, I pr ...

Selection from a list will not be enforced by value when utilizing ngDefaultControl in Angular

When I have a list of options and utilize the Angular directive ngDefaultControl, the form control's value appears empty upon button click. I am seeking a way to bind the value to the form control on button click without relying on the setValue or pat ...

Place a "sticky" button directly below a second "sticky" navigation bar

Within my app file, I have customized components like an appbar and various page elements: const styles = theme => ({ appBar: { width:'100%', }, }); class App extends Component { render() { const {classes} = this.props; ...

The animation using Jquery and CSS is experiencing some glitches on Safari when viewed on an

Why is smooth animation not working on iPad Safari with jQuery animate? $('#myId').css({ 'left': '-100%' }).animate({ 'left': '0' }, 300, 'linear'); I also tried using the addClass option and in ...

Exploring the depths of recursive descent parsing and the intricacies of abstract

As I dive into creating a recursive descent parser from scratch for educational purposes, I've encountered some challenges along the way. To illustrate my point, let's take a quick look at a snippet of the CSS3 grammar: simple_selector = type_s ...

Is there a way to turn off predictive text for reCAPTCHA on my mobile device?

Using reCAPTCHA on a sign-up form can get frustrating on mobile devices, with constant dictionary word suggestions while typing. I am aware of how to disable this feature for normal input fields by adding attributes through JavaScript, but shouldn't ...

Unable to see the cursor pointer in CSS

I have gone through all the previous discussions, but I am still unable to solve this issue. When I hover over a button with the cursor set to pointer, it does not work as expected. Additionally, the hover effect is also not functioning properly. I have in ...

I'm still undecided on what script I should use

I am striving to achieve a specific outcome, which can be found at this link http://farm8.staticflickr.com/7291/11250276724_fc1f751dc0_o.png. This image represents the desired end result. Regrettably, I am uncertain of the script required to accomplish t ...

How to align an element in the center using flexbox while considering the width of the display rather than the available

I need help centering an element that is 100px in width on the display. On either side of this element, there are elements that are 300px and 200px wide. I tried using flexbox to achieve this, but I ended up with two empty spaces or flexible-width element ...

Is it possible to share deep links with just a hashtag?

I am currently developing a web application and I want to include social media buttons such as Facebook Like. I have tried using the HTML code/API provided by Facebook, AddThis, Shareaholic, ShareThis, but none of them seem to properly handle my deep link ...

What steps should I take to repair my image modal button?

Within my application, I have an image modal placed inside a header tag, along with a label. There is some space between the label and the image modal. However, when the application is run, the page appears in a fixed position, but the label message does n ...

Use jQuery to create rows within each div

Can someone assist me with the following issue? I have created an HTML grid where objects are displayed on the left side, and a row is shown for each object on the right side. I am looking to use jQuery to add 8 items in a row on the right side for each o ...

Tips for Editing an HTML File

As a beginner in the world of coding, I am currently working on creating a quiz maker. My question is how can I use code to edit a file? For example, if a user inputs a question name, how can the code automatically update the corresponding question in th ...

Is it just me, or does the float left - float right combination only break in IE

Oh dear, it seems like IE9 is causing some trouble again. The other "capable" browsers handle this HTML just fine, including IE8 which isn't even that great. Here's the code snippet: <div class="contact_info_city" id="contact_info_cityX"> ...

Software communicating with the internet

What programming knowledge do I need to have in order to interact with the web using C++? For example, I want to create a program that automates sending invites to players on Yahoo Chess. How should I approach this task? ...

Connecting mysql workbench data using html: A step-by-step guide

I'm currently creating a user interface for a database system using HTML. I'm a bit stuck on how to access and manipulate the database in MySQL Workbench. Does anyone have any suggestions or sample code that could help me connect them? Thanks! ...