What is the best approach for organizing a CSS grids template?

I am trying to utilize CSS grids to arrange the layout of this page as shown below:

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

While there are currently only 3 divs, I want to begin by figuring out how to position div 2 and div 3 on the second row in columns 2 and 3. Should I use a total of 4 columns or stick with 3?

This is what my progress looks like so far:

.grid{
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 50px;
    box-sizing: border-box;
 
}
 .feature-one{
        grid-template-columns: 1/2;
    
  }
  .feature-two{
    grid-column: 3/6;
    grid-row: 2;
}
.feature-three{
    grid-column: 3/6;
    grid-row: 2;
}

Here is the current output of my work: https://i.sstatic.net/Rb9uD.png

Answer №1

Is this the solution you were searching for?

    .grid-container {
      display: grid;
      grid-template-columns: repeat(3, 30vw);
      grid-template-rows: 100px 100px;
      grid-gap: 13px;
      padding: 2px;
    }

    .grid-container>div {
      background-color: aqua;
      text-align: center;
      font-size: 15px;
    }

    .the-feed {
      grid-area: 1 / 1 / 3 / 1;
    }
  <div class="grid-container">
  	<div class="the-feed">The Feed</div>
    <div class="">Contact Lifecycle</div>
    <div class="">Custom Fields</div>
    <div class="">Custom Sales Activities</div>
    <div class="">Multi-Currency</div>
  </div>

Your layout consists of 3 columns that fill the entire screen width. You can set up the columns as follows:

  grid-template-columns: repeat(3, 30vw);

Additionally, there are two rows of equal height. You can define the rows like this:

grid-template-rows: 100px 100px;

If you wish to have the second row taller than the first, you can adjust the code like so: grid-template-rows: 100px 150px;

To span a div across two rows, use this line of code:

.the-feed {
	grid-area: 1 / 1 / 3 / 1;
}

The syntax may seem complex at first. Essentially, it instructs the div to start at gridline-row 1 and gridline-column 1 (e.g. 1/1), and end at gridline-row 3 and gridline-column 1 (e.g. 3/1).

Remember, gridlines are the lines between columns and rows, not the actual columns or rows. In a tic-tac-toe CSS grid, there are 3 rows and 3 columns but 4 row-grid-lines and 4 column-grid-lines. Refer to Why are CSS Grid-Area ending coordinates offset?

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

Encountering an error when attempting to iterate over an undefined property using an API

I am trying to fetch all classes and their assignments from Google Classroom. I successfully used Google's example code for listing the classes, but had to write my own code for listing the assignments. While the code runs as expected and lists the as ...

The functionality of the Toastr "options" seems to be malfunctioning

I am having some trouble with my Toastr notification messages. While the message does display, I seem to be unable to make use of any options that I set. Despite specifying some options, they do not seem to work as intended. $('#editButton').c ...

Customizing the search dialog in JQGrid to adjust the width of the input fields

Can the width of the text box in Jqgrid default search dialog be increased? Check out the image: Updated Code for the search functionality: jQuery("#subscriptions").jqGrid( 'navGrid', '#pager', { del: false, add: false, e ...

Unable to enclose a table within a div element for Chrome web browser

I attempted to keep a table within a div to ensure that the table's width does not go beyond the width of the containing DIV. This table consists of one row with two elements. The second element is fixed in length, while I want the first element to w ...

Split up Python Flask files into individual components

After researching extensively on stack overflow, I find myself facing a challenging issue that I am unsure how to resolve. The content of my main.py file is as follows: from flask import Flask, jsonify, request from flask_pymongo import PyMongo from bso ...

Applying the Directive/Isolated Scope as Embedded HTML within an Angular-Bootstrap Popover

If you're using the angular-ui popover, you have the ability to include HTML content within it. However, I encountered some difficulties in placing a directive called sampleDirective inside the popover. Despite my attempts with the $sce.trustAsHtml an ...

Formulate a multi-line string using a collection in React's JavaScript framework

I'm working on a React function that involves a set and I need to update an HTML element using the data from this set. Below is an example of my code: const updateElement = (mySet) => { document.getElementById('myId').innerHTML = Arra ...

Unable to access current props within useEffect block

When I use useEffect with the parameter props.quizStep, my function fn (which is a keydown event listener) is unable to access the current value of props.quizStep. I'm puzzled as to why it's not working properly. Can you help me understand? Bel ...

An unexpected identifier error occurred following an Ajax request

Below is the HTML code that I am working with: <div id="texttheory" class="centertext">'. $short .' </div>'; <button id="thbutton" class="theory_button" onclick="javascript:changetheory('.$long.')"> <im ...

Is there a way to align the Title in the Titlebar to the center?

Hi there! I could use some assistance :) I have an Electron app and I'm working on the title bar. I would like to center the title, but I'm not sure how to do it. Can anyone provide guidance on this? Also, since I am a beginner, I'm unsure i ...

passport.js and express.js working together to seamlessly redirect users back to the original page after completing oauth authentication

How can I navigate users to the same page after an OAuth request to Twitter by setting a session variable? Here is how the routes are currently configured: // Authentication routes (function () { app.get('/auth/twitter', passport.authentica ...

Make sure to not update until all the necessary checks have been completed successfully

My goal is to update an array of objects only after all the necessary checks have passed. I have one array of objects representing all the articles and another array of objects representing the available stock. I want to make sure that all the articles ar ...

Displaying Component when Clicked using Vue.js

How can I display a modal component after an "on click" event? Is it possible to show a component using a method call, or what is the recommended approach in this scenario? Here is my specific use case: I have multiple cards each containing various infor ...

Switching the position of a Button in Semantic UI React: Moving it from the Left to the

I need assistance with adjusting the position of a Semantic UI React Button. By default, the button is displayed on the left side, but I would like it to be on the right side instead. Can someone please provide guidance on how I can move the Semantic butto ...

Achieve perfect alignment both vertically and horizontally within a container-fluid using Bootstrap

As the heading suggests, I'm having trouble centering content inside a column within .container-fluid in Bootstrap 4. Below is the code I'm using, but I can't figure out what's wrong. Can someone please assist me? <link href="htt ...

The HTML5 date picker maintains its orientation when the body is set to right-to-left (RTL

I am working on a material UI React application that can switch to 'RTL (Right To Left)' in the appropriate time zones. However, I have noticed that the HTML5 date picker I am using does not flip when the body is in RTL mode. On the other hand, i ...

Concealing an element from a separate module

In the angularjs single page application project that I'm working on, there are two modules: module-'A' and module-'B'. Each module has its own view templates. The view template of module-'B' contains a div with id="sit ...

React-tooltip and a challenge with Server-Side Rendering in Next.js

In my Next.js app, I make use of the react-tooltip library for tooltips. One peculiar issue that I have noticed is that whenever I refresh a page containing a tooltip, I encounter the following error: react-dom.development.js:88 Warning: Prop `dangerously ...

Using Vue3 and Vuex4: How to efficiently render only a subset of items from an array with v-for

Hello, I'm a first-time user and beginner developer seeking some assistance. I am in the process of creating a basic web application that retrieves an HTTP JSON response from an API and displays a more visually appealing list of results. However, I&ap ...

Button element experiencing unexpected issues with ng-disabled in AngularJS

I've implemented a new button that should be active when the page loads and then disabled when data is being saved (using a save button). Essentially, this new button should be inactive whenever the save button is active. Angular code : <input id ...