I am in need of setting up two rows side by side using the display

I'm trying to have two rows side by side using display grid, but I'm facing some issues. When I use the following CSS...

.grid-container {
display: grid;
grid-template-rows: auto auto;
grid-template-columns: auto;
grid-column-gap: 100px;}

It creates two vertical rows and one column. But when I modify it like this...

.grid-container {
display: grid;
grid-template-rows: auto auto;
grid-template-columns: auto auto;
grid-column-gap: 100px;}

It creates two columns side by side and two vertical rows as shown in this image https://i.sstatic.net/ozZDv.png.

However, when I click my accordion button, the issue arises as shown in this image https://i.sstatic.net/SJce6.png.

Both columns take up height when clicked, which is not what I want. One solution could be creating two separate rows side by side, or if anyone has different suggestions, it would be greatly appreciated. I'm feeling too exhausted right now to think about the logic behind this problem. Thank you :)

Answer №1

While you may prefer to utilize display: grid properties, I haven't been able to achieve the desired result using those properties. Instead, I propose an alternative approach by employing display:flex.

In the demonstration below, I utilized Bootstrap's accordion feature.

1) To align direct children elements (blocks/divs) next to each other, apply some display:flex to a container.

2) Create 2 child blocks within that container to establish 2 columns. You can use bootstrap's col-6 class for each block, setting its width to 50%.

3) Within these 2 columns, insert your accordions while ensuring they function independently without affecting neighboring elements in the opposite column.


This is how it appears visually:

https://i.sstatic.net/lrGaq.png


If you're interested, here's a code snippet utilizing Bootstrap 5.1.3 :

<html lang="en">
    <head>
        <!-- CSS only -->
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f3919c9c878087819283b3c6ddc2ddc0">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
      <link rel="stylesheet" href="./styles.css">
        <meta charset="utf-8">
        <title>Document</title>
    
    </head>
    <body>
      <div class="d-flex">
        <div class="col-6">
          <div class="accordion" id="accordion-1">
            <div class="accordion-item">
                // Accordion content goes here
            </div>
          </div>
        </div>
        <div class="col-6">
            // Second set of accordion items go here
        </div>
      </div>

          <!-- JavaScript Bundle with Popper -->
      <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed8f8282999e999f8c9dadd8c3dcc3de">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
    </body>
    </html>


-- UPDATE --

I've devised another method that leverages display:flex, but incorporates more structural adjustments to uphold responsive design standards as per your specifications:

  • on mobile / tablet: Implement a horizontal layout with two elements side by side. Accordions won't impact the height of adjacent elements when expanded.

  • on desktop / large screens: Utilize a vertical layout instead

Below is a code excerpt, feel free to test the responsiveness to witness the structural adaptations.

<html lang="en">
    <head>
        <!-- CSS only -->
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="40222f2f34333432213000756e716e73">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
      <link rel="stylesheet" href="./styles.css">
        <meta charset="utf-8">
        <title>Document</title>
    
    </head>
    <body>
        <div class="col-12 col-lg-4">
          <div class="row">
            <div class="col-6 col-lg-12">
              <div class="accordion" id="accordion-1">
                  // First set of accordion items inside this div
              </div>
            </div>
            <div class="col-6 col-lg-12">
                // Insert second set of accordion items here
            </div>
          </div>
        </div>

           <!-- JavaScript Bundle with Popper -->
        <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92f0fdfde6e1e6e0f3e2d2a7bca3bca1">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
    </body>
    </html>

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

Navigation is failing to float in the correct position

Having issues with my navigation positioning, specifically when it reaches the breakpoint. There's a strange gap on the right side that I can't seem to fix by adjusting padding or margin settings. I'm relatively new to this so please bear wi ...

Modify the characteristics of a bootstrap button depending on certain conditions

I am working on enhancing a bootstrap dropdown button by implementing a functionality where it will be disabled if certain conditions are met. Below is the current code snippet for the button: <> <DropdownButton title={fixtureDetails.h ...

Is there a way to allow users to edit all the input fields within the td elements when they click the edit button for a specific row?

I am completely new to web dev and I'm struggling with what should be a simple task. My goal is to enable editing of all inputs in a table row when the edit link is clicked. Since I am not using jQuery, I prefer a pure JavaScript solution if possible. ...

Django positions the save button

Is there a way to update the data in this column using a form, display and save the data, and also add a delete button? I'm seeking a solution for this issue. models.py class Employe(models.Model): Matricule = models.CharField(max_length=10, null=Fal ...

retrieve data with the help of DOMDocument

I'm currently working on extracting a specific value from the HTML snippet below using DOMDocument: <h3> <meta itemprop="priceCurrency" content="EUR">€ <meta itemprop="price" content="465.0000">465 </h3> The value ...

Samsung mini devices experiencing issues displaying Unicode symbol (25be)

I'm currently facing an issue with an iconfont that I have included in my website. I am using Unicode symbols for the characters of the icons, and most of them are displaying correctly. However, there are a couple that are showing up as blank on the s ...

Embedded HTML code within a table cell

How can I dynamically build an HTML string and display it inside a cell in reactJS' ag grid? Here's my example: function generateHtmlString(props) { let myHtmlString = "<span>a</span>"; myHtmlString += "--"; myHtmlString += "&l ...

Tips for implementing an HTML modal with AngularJS binding for a pop up effect

As a beginner in AngularJS, I am facing a challenge. I have an HTML page that I want to display as a pop-up in another HTML page (both pages have content loaded from controllers). Using the router works fine for moving between pages, but now I want the s ...

Completing a form and saving data to a document

I have a form that successfully writes to a text file using PHP. However, after submitting the form, the page reloads and shows a blank page. Currently, there is a message that appears using jQuery after the form is submitted. My goal is to prevent the pa ...

Having trouble with the scrolling feature on a read-only text area within a form

My form allows users to input their data, but once submitted, the form becomes read-only. However, I'm facing an issue where the data in the text area is not scrollable even though it should be. I need assistance in figuring out why the content in th ...

Could anyone provide some insight into the reason behind this occurrence?

I just came across the most peculiar situation I've ever experienced. Check out this unique test page: <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title></title> <script language=javascript> fun ...

Creating separation between a dropdown menu and its corresponding button

I'm dealing with a situation where I have a button that reveals a hidden droplist upon hover. The problem is that there is no space between the button and the droplist, causing interference with the functionality. My attempt to create some distance b ...

How is it that the magic table refuses to conform to CSS styling? This is truly sorcery!

My HTML table is as simple as it gets: <table class="dispdtab"> <tr> <td><b>Dealer: </b></td> <td>dealername</td> </tr> <t ...

The flipping CSS code will not be compatible with IE 11

I'm experimenting with creating a flip animation that reveals link text when images are flipped. Everything works fine in most browsers, except for IE11. Apparently there's an issue with transform-style: preserve-3d; in IE10, but being new to CS ...

Unable to access the button with Selenium clicking functionality

<button class="css-obkt16-button" type="button"><span class="css-1mhnkuh">Download CSV</span></button> I'm attempting to select the highlighted 'Download CSV' button https://i.sstatic.net/SThoW.png with the HTML code ...

Exploring Vue's data binding with both familiar and mysterious input values

How can I model an object in Vue that contains both known and unknown values? The quantity is unknown, but the type is known. I need to present user inputs for each type, where the user enters the quantity. How should I approach this? data() { retur ...

I'm currently in the process of creating a snake game using HTML5. Can you help me identify any issues or problems that

I am experiencing an issue where nothing is appearing on the screen. Below are the contents of my index.html file: <html> <body> <canvas id="canvas" width="480" height="480" style="background-color:grey;"></canvas> <script src=" ...

Angular Material's <mat-select> tag allows for the inclusion of an <input> element within it

I am attempting to place an input element inside the mat-select tag of the Angular Material element. However, I am facing an issue where I cannot input any text into the input field inside the select element. Below is the code I am using to search for elem ...

Modifying the Vue.js Vue3-slider component for custom color schemes

Currently, I am using the vue-slider component and would like to customize the color of the slider itself. The specific class that needs to be styled is "vue-slider-dot-tooltip-inner". Below is a screenshot displaying the original CSS styling for vue-slid ...

Navigate to a specific hidden div that is initially invisible

Currently, I am working on a web chat application using next.js. The app includes an emoji picker button, which, when clicked, displays a menu of emojis. However, the issue I am facing is that the user has to scroll down in order to see the emoji menu. I a ...