CSS: What is causing my three columns to divide?

I am encountering CSS issues while attempting to develop a React app using Next.js.

Here is the content of my home.module.css:

.grid_container {
  /* display: grid; */
  /* grid-template-columns: auto auto auto; */
  /* column-count: 3;
  align-items: flex-start; */
  /* align-content: space-evenly; */
  align-items: stretch;
  column-count: 3;
  /* column-gap: 500px; */
  border: solid;
  width: 100vw;
  height: 100vh;
}

.left_pane {
  justify-content: left;
  border-style: solid;
  float: left;
  width: 25%;
  height: 300px;
}

.center_pane {
  justify-content: left;
  border-style: solid;
  float: left;
  width: 50%;
  height: 300px;
}

.right_pane {
  justify-content: left;
  border-style: solid;
  width: 25%;
  float: right;
  height: 300px;
}

Next, here is index.js:

export default function Home() {
  return (
    <div className={styles.grid_container}>
      <div>
        <div className={styles.left_pane}>
          <h2>Left Pane</h2>
        </div>
        <div className={styles.center_pane}>
          <h2>Center Pane</h2>
        </div>
        <div className={styles.right_pane}>
          <h2>Right Pane</h2>
        </div>
      </div>
  )
}

Observation: https://i.sstatic.net/6K46K.png

Why are the columns wrapping instead of occupying the entire frame as intended?

.grid_container {
  /* display: grid; */
  /* grid-template-columns: auto auto auto; */
  /* column-count: 3;
  align-items: flex-start; */
  /* align-content: space-evenly; */
  align-items: stretch;
  column-count: 3;
  /* column-gap: 500px; */
  border: solid;
  width: 100vw;
  height: 100vh;
}

.left_pane {
  justify-content: left;
  border-style: solid;
  float: left;
  width: 25%;
  height: 300px;
}

.center_pane {
  justify-content: left;
  border-style: solid;
  float: left;
  width: 50%;
  height: 300px;
}

.right_pane {
  justify-content: left;
  border-style: solid;
  width: 25%;
  float: right;
  height: 300px;
}
  <div class="grid_container">
    <div class="left_pane">
      <h2>Left Pane</h2>
    </div>

    <div class="center_pane">
      <h2>Center Pane</h2>
    </div>

    <div class="right_pane">
      <h2>Right Pane</h2>
    </div>
  </div>

Answer №1

When using CSS grid, you can set the column widths in the grid-template-columns property and the row heights with the grid-template-rows property. Floats and the width property are not necessary. Also, since a div element is block-level by default, it spans the full width of its container. Make sure that the elements directly inside your container define the columns; avoid unnecessary wrapping divs.

If you need more guidance, check out this resource.

.grid_container {
  display: grid;
  grid-template-columns: 25% 50% 25%;
  grid-template-rows: 100px;
  column-count: 3;
  column-count: 3;
  border: solid;
}

.grid_container .pane {
  justify-content: left;
  border-style: solid;
}
<div class="grid_container">
  <div class="pane">
    <h2>Left Pane</h2>
  </div>
  <div class="pane">
    <h2>Center Pane</h2>
  </div>
  <div class="pane">
    <h2>Right Pane</h2>
  </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

Use jQuery to create a price filter that dynamically sets slide values based on the filter object

I'm currently utilizing the jQuery slide filter to sort products based on price. The filtering value is set within the script, but I am interested in dynamically setting it based on the highest/lowest number found on my page using a data attribute. D ...

How can I incorporate a .shtml file into a .php webpage?

Is there a way to include a .shtml file within a .php page? I know it can be done, as I have successfully achieved this in the past (although I cannot remember the exact code). Can someone please assist me with this? ...

Tips for locating a file using javascript

My application scans a folder and displays all folders and HTML files inside it in a dropdown menu. It also shows any HTML files inside an iframe. There is one file named "highlighted.html" that should not appear in the dropdown menu, but if it exists in t ...

What is the process for assigning default values to dynamically generated form elements?

I have been working on building a single-page application (SPA) using JavaScript and jQuery. During the process, I encountered an issue with a dynamic form. The user is able to add specific fields as needed, but if they don't generate and utilize all ...

Having trouble with positioning divs on top of each other? Struggling to get position absolute to work correctly?

Currently, I am utilizing flexbox to construct a grid layout. However, I have hit a roadblock when attempting to make the divs stack on top of each other. The overflow:auto is hidden and position relative has been added to the carddiv. While the divs are s ...

What is the best method for placing text over an image in Dreamweaver?

What steps should I take to overlay text on an image using Dreamweaver? Similar to the example linked below: https://i.stack.imgur.com/8GvkW.png Below is a snippet of my code: HTML <body> <main> <header> <img src="images/headerimag ...

Looking for a smart way to extract all the selected elements from a form?

I am attempting to retrieve all the checked items from this form using JavaScript. I have looked at previous solutions, but none of them fit my requirements. <form id="checkform" class="container" style="margin-top:20px;"> <input type="checkb ...

Error message: ngRepeat does not allow duplicate elements in an array

Upon review, I discovered this particular piece of code: <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <body> <script> var app = angular.module("myS ...

Animating a spinning SVG path around its center within a larger rectangular box

Is there a way to rotate a smaller SVG path within a larger rectangle around its own center? The current code rotates the entire space. <animateTransform attributeType="xml" attributeName="transform" type="rotat ...

varying perspectives in different browsers within my React application

I'm experiencing inconsistencies in the appearance of my website when viewed on Chrome mobile compared to Safari on an actual phone. Despite using prefixes for all my styles (WebKit, etc.) and incorporating normalize.css to address any issues, the dis ...

Having trouble triggering a click event with JQuery

I have a hidden link for downloading Audio Files that I want the user to access using a button. However, I am having trouble triggering the click event. Below is the HTML code: <a class="APopupDown" data-icon="home" id="DownloadFile" href="http://yaho ...

Perform validation on input by monitoring checkbox changes in Angular 4

I am currently working on a project where I need to loop through an array of key values in order to create a list of checkboxes, each accompanied by a disabled input field as a sibling. The requirement is that upon checking a checkbox, the corresponding in ...

Can the JavaScript code be altered within the client's browser?

So, I'm using JQuery Validator on my webform to validate form data. However, I haven't added any validation on the server side. I'm curious if it's possible for a user to modify the code and bypass my validations in their browser. If th ...

Is there a way to change the button design within the CSS code of Mailchimp's embed feature?

Struggling to customize the button style and positioning in Mailchimp's embed CSS: <!-- Begin Mailchimp Signup Form --> <link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/c ...

Looking for an alternative to document.querySelectorAll?

My issue involves using querySelectorAll('a') to select all buttons, but I only want to target two specific buttons labeled 'Know More'. How can I achieve this? Below is the code snippet in question: const buttons = document.query ...

Mapping an array in ReactJS based on the specific order of another array

In my experience with Unmitigated, the answer proved beneficial. If you're arriving from a Google search, please scroll down for more information. Order: [ "567", "645", "852", "645", "852", "852 ...

The form created using jQuery is not submitting correctly because the PHP $_FILES array is empty

Creating an HTML form dynamically in jQuery and submitting the form data via Ajax to 'add_sw.php' for processing is my current challenge. However, I have encountered an issue where the PHP script cannot access the PHP $_FILES variable as it turn ...

What is the best method to activate a button only when the appropriate radio buttons have been chosen?

Just dipping my toes into the world of javascript. I've created a form with a set of "Yes/No" radio buttons, and I attempted to create a function that will disable the "Submit Form" button if any of the following conditions are met: If one or more r ...

Inspect Element - base tag href URL for inline CSS allocation

When utilizing the <base> tag in HTML along with the <style> tag on Microsoft's Edge Browser, I encounter a peculiar issue. Here is a very basic example: <!DOCTYPE html> <html lang="en"> <head> <title>Edge de ...

When an external image is dragged over, include the class in the drop area of the file input

Hey, does anyone know how to use Jquery to add a class when an element is being dragged over a drop area? Here's the HTML code I'm working with: <div class="upload"> <form action=""> <input class="uploadfile" type="file" ...