Set up four divs in a cascading arrangement across four separate columns

Looking to set up 4 cascading divs that create the appearance of being in 4 columns.

Here is the given html structure (unable to be modified)

<div class="col1">
    1111
    <div class="col2">
        2222
        <div class="col3">
            3333
            <div class="col4">
                4444
            </div>
        </div>
    </div>
</div>

The goal is to achieve the following layout when implemented:

display: grid;
grid-template-columns: repeat(4, minmax(200px, 1fr));

Attempts were made with grid-template-areas but did not produce the desired outcome.

Answer №1

Clarification on previous response.

Apologies for the confusion in my earlier answer where I mistakenly stated "I can modify it" instead of correctly stating "I can't modify it". I am sorry for any inconvenience this may have caused.

Updated Response

To achieve a grid-like structure when all children are at the top level with specific CSS styling, some mathematical calculations are required. While this method might be a bit challenging to maintain if there are changes, it will yield the same results as using a grid div element.

.col1{
  display: grid;
  grid-template-columns: minmax(200px,1fr) minmax(600px,3fr);
}
.col2{
  display: grid;
  grid-template-columns: minmax(200px,1fr) minmax(400px,2fr);
}
.col3{
  display: grid;
  grid-template-columns: minmax(200px,1fr) minmax(200px,1fr);
}
<div class="col1">
    1111
    <div class="col2">
        2222
        <div class="col3">
            3333
            <div class="col4">
                4444
            </div>
        </div>
    </div>
</div>

Explanation

When utilizing a grid with a min-max layout repetition, each element must conform to the minimum and maximum specifications set. In the nested setup described, col1 should encompass the width of all children within it. The first child should adhere to a min-max of 200px and 1fr, while subsequent children's widths should be adjusted accordingly to create multiple columns. This Codepen example demonstrates how the div sizes align with your specified CSS styles, ensuring consistency even with further additions or modifications. While the defined classes may seem repetitive, a pure HTML/CSS alternative with similar functionality is hard to come by.

I hope this explanation proves helpful. Thank you!

Answer №2

To achieve a similar layout, consider utilizing flexbox properties

[class*=section] {
  display: flex;
  flex: 1;
  gap: 10px;
}
<div class="section1">
  Content 1
  <div class="section2">
    Content 2
    <div class="section3">
      Content 3
      <div class="section4">
        Content 4
      </div>
    </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

Switching between dark and light mode in Ant Design

I have successfully implemented dark mode toggling in my application. However, when I try to switch back to light mode, the CSS does not seem to be reloading properly. Below is the code snippet: //ThemeContext.jsx const DarkTheme = lazy(() => import(". ...

Increase the identifier of my input text when a table row is duplicated through Javascript

I have a table with only one row that contains various elements like textboxes and buttons. I want to clone the table row using the append() function when a button is clicked. However, I am facing an issue - how can I increment the id of the textboxes and ...

Discover the specific span being modified within a div

Recently, I coded some HTML: <div id="contentbox" contenteditable="true"><span value="1">Hello</span><span value="2">Stack</span><span value="3">over</span> flow</div> Additionally, I used jQuery to enhance ...

Steps to bold a specific word within a div on react native

Hey there! I'm working with the code below: getDescription = () => { return( <div className="Description">{this.props.mytext + ': ' + this.name} </div> ) } Is it possible to bold only the specific te ...

How can I determine the specific quantity of XPATH links with unique identifiers in Selenium?

Seeking automation with Python3 and selenium to streamline searches on a public information site. The process involves entering a person's name, selecting the desired spelling (with or without accents), navigating through a list of lawsuits, and acces ...

Is it possible to accomplish this using a list or a table in HTML/CSS?

I am currently working on creating a visual representation of a color catalog using hyperlinked images. My goal is to have a layout that displays the colors in a grid format, similar to this: However, the number of images per row may vary depending on the ...

How to deselect a checkbox in next.js when another one is selected

I'm looking to create a navigation system where clicking on a button scrolls to a specific section. However, I'm wondering how to deselect three inputs when one is selected in next.js using the code below. Do I need to modify each menu item indiv ...

Displaying an interactive 2D floorplan in a web browser with the use of html5 and javascript

In the process of updating my old Flash viewer, I am looking to display interactive 2D floorplans exported from AutoCAD. Currently, I convert the AutoCAD files into XML files containing the X and Y coordinates of the various elements on the floorplan such ...

When incorporating inline-block styling in dompdf, it may result in added space below the elements

One issue that arises when there are multiple elements with display:inline-block is that these elements can sometimes display with a margin below them after being rendered as a PDF: <div style="background-color:pink;"> <div style="background- ...

The hover effect is failing to impact a child element during a transition

I created a link with an arrow next to it that should move 20px to the right when hovered over, using a transition of 1s. However, for some reason the transition is not affecting the arrow. Can anyone please assist me in figuring out why this is happenin ...

Design your website with CSS by incorporating hanging ::before labels that feature unique formatting

I am looking to create labels that designate specific groups of words. Here are the criteria: The label should appear to the left of the word group The words should be enclosed in lines, while the label should not The words should be indented, while the ...

Add an event listener to a specific class in order to control the visibility of its child elements by

Whenever I click on the "title text" link, the <ol> element refuses to hide, despite my efforts. After thoroughly reviewing the jQuery documentation and scouring Stack Overflow for answers related to .click(), .children(), .toggle(), and .hide(), I a ...

What is the best method to retrieve text from a <span> element within an <li> element nested inside a <ul> using BeautifulSoup?

I need help extracting the content from the Here’s what’s new section on this page. Specifically, I am trying to capture everything between In the coming weeks and general enhancements. After inspecting the code, I noticed that the <span> elemen ...

Does the Width Toggle Animation fail to function in FireFox when using jQuery?

Has anyone else encountered this issue with the jQuery animate function not working in Firefox but working fine in IE8, Opera, and Chrome? I'm experiencing this problem and wondering if there's a workaround to make it work in Firefox as well. ht ...

The webpage contains duplicate ID attribute value "x" that has been identified

In my Angular 7 project, three components (a, b, c) all use an input element with the same id of "x". However, component b has 4 input elements all using the id "x" as well. This poses Accessibility Issues as ids must be unique. The test cases utilize &apo ...

Can this functionality be accomplished using only HTML and CSS, without relying on JavaScript?

Image for the Question Is it possible to create a zoom functionality using only HTML and CSS, without relying on JavaScript? I need this feature for a specific project that doesn't support JavaScript. ...

Element with a fixed position within an iScroll container

Has anyone encountered an issue with fixing an element with position: fixed inside a big Iscroll page? It seems like the element scrolls along with the content due to the transition imposed by Iscroll. I'm trying to fix the "FIXTHIS" element, but it ...

Guidelines for ensuring that a radio button must be chosen prior to submission

I'm struggling with implementing AngularJS validation for a set of questions with radio answer choices. I want to ensure that the user selects an answer before moving on to the next question by clicking "Next". Check out my code below: EDIT: Please k ...

"Is it possible to trigger a JavaScript function within an HTML file from a servlet in Java in order to update the

Is there a way to invoke an HTML JavaScript function from a servlet in Java that will update the content of the HTML page? Could you please provide me with a sample example? I have one server-side servlet that writes data which needs to be updated in ano ...

Sending a POST request using HTML

Recently, I decided to create a URL Shrinker for fun and followed the Traversy Media tutorial to build it. If you're interested, here's the GitHub link to his project: https://github.com/bradtraversy/url_shortener_service As I aim to turn it in ...