Non-sibling grandchildren using Flexbox

Check out this example to see what I'm aiming for.

I am looking to achieve a DOM structure as follows:

<div class="parent">
  <div class="child">
    <div class="grandchild flex-3">
      Wide Grandchild
    </div>
    <div class="grandchild flex-1">
      Narrow Grandchild
    </div>
  </div>
  <div class="child">
    <div class="grandchild flex-2">
      Medium Grandchild
    </div>
  </div>
</div>

My aim is to have the grandchildren's flex properties act like siblings.

Here is my current CSS code snippet:

.parent {
  display: flex;
}

.grandchild {
  background-color: rebeccapurple;
  color: #ddd;
  padding: 6px;
  border: solid 2px #ddd;
}

.flex-1 {
  flex: 1;
}

.flex-2 {
  flex: 2;
}

.flex-3 {
  flex: 3;
}

This is how I want it to look:

Narrow Grandchild | Wide Grandchild Medium Grandchild

However, this is how it currently appears:

Answer №1

I have successfully replicated the design you were aiming for and have made updates to your JSBin.

<div class="parent">
  <div class="child child-flex flex-2">
    <div class="grandchild flex-3">
      Wide Grandchild
    </div>
    <div class="grandchild flex-1">
      Narrow Grandchild
    </div>
  </div>
  <div class="child child-flex flex-1">
    <div class="grandchild flex-2">
      Medium Grandchild
    </div>
  </div>
</div>

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

Is it possible to adjust the width of a parent element based on the number of child

In this particular example, I have structured a header with a logo-container positioned on the left side, a menu in the center, and a button on the right. The menu consists of 5 top-level items and 2 sub-menus. <div class="container"> <div cla ...

PHP submits blank Form data to the Server

Despite the PHP server confirming the connection, the values entered in the form are not being stored and result in empty table rows. Below is the PHP code snippet: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> ...

How can I adjust a large image to fit the browser window using CSS?

I have a large image (3000px by 2000px) that I want to use as the background for my website and adjust it to fit the window size. Currently, I have implemented the following CSS: body { background: url('image.jpg') !important; background ...

Tips on utilizing emmet effectively through copy and paste

When I have an emmet snippet like this one: .row>.col>(.row>.col.bg-sucess>br*2)+(.row>.col.bg-danger>br)+(.row>.col.bg-warning*3) and I paste it into my vscode from any source, it doesn't register as an emmet snippet. So I ofte ...

Activate an element in Polymer 2 by clicking on another

After working with Polymer 2, I successfully developed two custom elements: A custom-designed button An overlay element Now, in another "main element," I have imported and incorporated both of these elements. The next step is to toggle a specific class ...

Understanding the outcomes of CSS media queries

I'm currently grappling with CSS media queries for a mobile-centric webpage. My main objective is to maintain consistent font sizes on the page, regardless of device physical size and resolution specifications that may vary. However, I am finding that ...

Show or hide a Div based on radio button selection problem

I've successfully implemented a Div visibility toggle using the code below: $('input[name="type"]').on('change', function() { var show = $(this).val(); $(".typechoice").hide(); $("#"+show).show(); }) <script src="h ...

Dynamic color change in SVG

I am facing an issue with changing the color of svg images in a menu list using the filter CSS property. Even though I have obtained the correct filter value from a library that converts hex to CSS filter, React seems unable to set this property on the ima ...

The issue with adding rows to a dynamic HTML Table in Angular is that it is causing the previous rows to disappear

I have created a neat HTML table with three columns: <table > <thead> <tr> <td class="tdBorderEmail"><label>Action</label></td> <td class="tdBorderEmai ...

Text alongside a perfectly aligned image

I'm facing a dilemma. I've been striving to replicate the layout of my training website blocks to look like this: http://prntscr.com/4cd4gm. However, aligning text and paragraphs has become an obstacle for me. Despite succeeding in aligning pictu ...

Update Calendar Information Without Reloading the Entire Page

Is there a way to automatically refresh a div that includes a FullCalendar Calendar? I'm looking to refresh the div every 30 seconds to check for new data from the database without having to modify the ViewModel or reloading the page. index.html &l ...

Is there a way to achieve a two-column layout using flexbox while maintaining consistent spacing between items in each column?

Hey there! I could really use some assistance. I'm attempting to create a two-column layout with consistent spacing between items in the same column. https://i.sstatic.net/hb5bT.png .flex { margin: 0; padding-left: 0; list-style: none; disp ...

CSS Styling Dropdown Menu for Internet Explorer 5 and Internet Explorer 11

I am encountering an issue with a select box that is coded as follows: <html:select property="list_data" size="12" style="width: 350px;" ondblclick="JavaScript:doOK()"> <html:optionsCollection property="list_data" label="codeAndNameLabel" val ...

Search for styling cues within the text and transform them into distinct elements

I was inspired to develop a unique text editor that utilizes cues within the text, such as :strong:, to set formatting rules. Here is the code snippet I have so far: <?php $document = $_GET["document"]; $user = $_GET["user"]; if ($user != n ...

Show images dynamically with the help of Flask

Imagine having a camera that can capture real-time images and save them to a folder named "./static". The goal is to showcase each processed image on a local web page using Flask in Python. This means that the system user will be able to view the results ...

What is the best way to establish personalized CSS styles specific to each subdomain?

I am in the process of establishing a multi-tenant application with a single instance and single database setup. The backend infrastructure is built using Ruby on Rails, while the frontend is handled by a separate AngularJS app integrated with a Rails fram ...

Discovering a sophisticated way to locate a span element using the not(p) selector in Selenium

Within a span element with an ID, there is a mixture of text and a paragraph tag. The goal is to use selenium webdriver to pinpoint the street address in the mix below: <span id="myspan"> <p>fullname</p> street address - has no ...

The Jquery code for Fullpage.js is causing unexpected behavior on the HTML page

While following a tutorial at the given link, I encountered an issue. Around the 9:08 mark, the instructor adds some JavaScript and demonstrates that fullpage.js is working. However, when I refresh the page after implementing the new code, it doesn't ...

The CSS in Node.js stubbornly refused to be implemented

I'm in the process of creating a straightforward application, and while setting up the project, I encountered an issue. I have a basic localhost server and an HTML file to display, but upon accessing the localhost, I received this error in the console ...

A dynamic, multi-column, two-dimensional layout using CSS Grid

Within my HTML structure, there exists a single container div followed by a variable number of child divs. The objective is to implement a multi-column layout for these child divs based on their respective class names. <div class="list-units"> & ...