How can I create a three-column layout in CSS grid where there is one large column on the left and two smaller columns on the right?

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

Hi there! I'm currently working on replicating the image above using CSS grid and I've almost got it, but I'm facing an issue with the main content section that includes "Your Projects," "Announcements," and "Trending." My goal is to have "Your Projects" take up a large portion of the grid, with "Announcements" and "Trending" positioned to the right of it. I've been trying to adjust the row sizes for each section so that "Your Projects" and "Announcements" expand while "Trending" remains a small box next to "Announcements," but I can't seem to get it just right. How can I make this work effectively?

html

                <div class="main-content-grid-container">
                <div class="projects-container main-content-grid">
                    <h1>projects</h1>
                </div>
                <div class="announcements-container main-content-grid">
                    <h1>announcements</h1>
                </div>
                <div class="trending-container main-content-grid">
                    <h1>trending</h1>
                </div>
            </div>

css

.main-content-container{
    background-color: #fafafa;
}

.main-content-grid-container{
    display: grid;
    grid-template-columns: 3fr 2fr;
    grid-template-rows: 10fr 1fr;
    
}

.projects-container{

}

.announcements-container{
}

.trending-container{
    grid-area: 2/3/2/2;
}

.main-content-grid{
    border: 2px black solid;
    background-color: goldenrod;
}

Answer №1

In a similar fashion:

* {
    margin: 0px;
    padding: 0px;
}

body {
    background: blue;
}

.mainContent {
    position: absolute;
    float: left;
    width: 65%;
    padding: 10px 10px;
    justify-content: center;
    align-items: center;
}

.rightContent {
    float: right;
    width: 30%;
    padding: 10px 10px;
    justify-content: center;
    align-items: center;
}

.card-box {
    background: red;
    position: relative;
    padding: 20px 10px;
    margin: 20px 0px;
    border-radius: 5px;
}

.card-box .inner {
    padding: 5px 10px 0 10px;
}
<!DOCTYPE html>

<html lang="en">

  <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>

  <body>
  
    <div class="mainContent">
      <div class="card-box">
        <div class="inner">
          test
        </div>
      </div>
    </div>

    <div class="rightContent">
      <div class="card-box">
        <div class="inner">
          test
        </div>
      </div>
    </div>
    
  </body>
  
</html>

Then proceed to generate 2 additional columns:

* {
    margin: 0px;
    padding: 0px;
}

body {
    background: blue;
}

.mainContent {
    position: absolute;
    float: left;
    width: 65%;
    padding: 10px 10px;
    justify-content: center;
    align-items: center;
    display: table;
    clear: both;
}

.rightContent {
    float: right;
    width: 30%;
    padding: 10px 10px;
    justify-content: center;
    align-items: center;
}

.card-box {
    background: white;
    background: red;
    position: relative;
    padding: 20px 10px;
    margin: 20px 0px;
    border-radius: 5px;
    
    /*Only for demostration*/
    height: 300px;
}

.column {
  background: green;
  width: 40%;
  padding: 10px;
  border-radius: 5px;
}
<!DOCTYPE html>

<html lang="en">

  <head>
      <meta charset="UTF-8>;
      <meta http-equiv="X-UA-Compatible" content="IE-edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>

  <body>
  
    <div class="mainContent">
      <div class="card-box">
        <div class="inner">
          <div class="column" style="float: left;">
            <p>test</p>
          </div>
          <div class="column" style="float: right;">
            <p>test</p>
          </div>
        </div>
      </div>
    </div>

    <div class="rightContent">
      <div class="card-box">
        <div class="inner">
          test
        </div>
      </div>
    </div>
    
  </body>
  
</html>

Answer №2

It appears that the goal is to keep the trending section within the right-hand column underneath announcements. To achieve this, you can enclose both announcements and trending in their own div:

<div class="main-content-grid-container">
    <div class="projects-container main-content-grid">
        <h1>projects</h1>
    </div>
    <div>
        <div class="announcements-container main-content-grid">
            <h1>announcements</h1>
        </div>
        <div class="trending-container main-content-grid">
            <h1>trending</h1>
        </div>
    </div>
</div>

You can then apply any desired spacing and styling to this new div containing both announcements and trending.

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

Add a new div in Javascript and include an HTML icon inside

This Django project includes a JavaScript function that generates a new div to display certain data. for (var i = 0; i < files.length; i++) { var newDiv = document.createElement('div'); newDiv.setAttribute("class" ...

Establish the lowest possible height for Angular Material Expansion Panel Content

Is there a way to specify a minimum height for the content of an Angular Material expansion panel when it is open? I have searched for examples on setting the expandedHeight and collapsedHeight for the header, but not for the content itself. The Angular Do ...

Add a CSS class to an innerHTML element just a single time

I currently have 2 files available: data.php page.php The data.php file is responsible for fetching a row from a SQL database and sending it to the page.php file. Within the page.php file, there is a JavaScript script that receives this row through AJAX ...

Can CSS Grid layout be used to generate a grid consisting of squares?

I'm trying to set up a grid with equal square dimensions, but I'm having trouble with it. I've explored CSS Grid as a possibility since I thought it allowed for the creation of squares of equal height and width within a grid layout. However, ...

Is Selenium Webdrive the superior choice over direct requests?

My goal is to extract verification sentences from Facebook pages using BeautifulSoup. The specific sentence I am looking for is "Verified PageFacebook confirmed this is an authentic Page for this public figure, media company or brand." I tried parsing the ...

Looping through a nested for loop within an HTML table

I am currently working on generating a dynamic table using Lists of varying sizes. My first list is a List of Cars List<Car>. I have successfully placed the names of different car companies in the header. Next, I have a List<List<CarSales>& ...

The script for Angular2 index.html cannot be included because it is not found

My index.html file looks like this: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Rock Star Messenger</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-sc ...

I'm curious if there is a tool available for comparing front-end testing results on a WordPress site, particularly to identify any differences before and after making updates

When updating plugins, there is always a risk of something breaking. Before proceeding with the update, it's a good idea to capture a screenshot or recording of the website using the provided tool. This way, you can compare the before and after versio ...

Unique style for custom vue multiselect component

I have implemented a Vue Multiselect component, but I am struggling to fully customize it with CSS styles. I have applied some CSS styles, but I am unable to achieve all the customization I want. Specifically, I want to modify the option height, select box ...

How can I use Selenium in combination with Python to retrieve the visible text of a selected radio button or checkbox on a webpage?

I am currently working on processing a form where I need to extract the text values of all checked radio buttons. Each line item will have one radio button checked. Here is an example of the HTML structure for a checked radio button: <div style="white ...

The symbol "#" appears in my URL whenever the link is clicked

Seeking guidance on a URL issue that I am facing. Whenever I click the source link, it adds a pound sign to the URL. How can I prevent this from happening? Can someone assist me in identifying the necessary changes required in my jQuery or HTML code? Bel ...

Sending a file along with other form data simultaneously

Currently utilizing ajax file upload to submit a file along with other form fields, but encountering issues with functionality. $.ajaxFileUpload({ url: './uploadtest.php', secureuri: false, fileElementId: 'userfile', d ...

Newbie inquiries regarding the process of migrating a CRUD application to PhalconPHP

I have recently delved into using PhalconPHP 1.3.1 for an application related to my master's thesis. While it is still a work in progress, I am currently focusing on implementing CRUD functionality and refining the user interface. This endeavor marks ...

Centered text in <td> with CSS aligned to the right

https://i.sstatic.net/UrB5f.jpg Is there a way to align the 3 input fields so that their right edges are all vertical? I still want the text+Input to be centered within the column but aligned vertically... Using Bootstrap 3.3.7 HTML: <link href="h ...

Navigating the rollout of a fresh new design

When implementing a new design on a website, how can you bypass the need for users to clear their browser cache in order to see the updated changes? Is there a way to automatically refresh the cache once a new version of the website is uploaded, or are th ...

Applying Bootstrap's inline styling to adjust the width of a label

I'm having trouble adjusting the width of a Bootstrap label using inline styles. Here is my code: <td><span class="label label-info" style="width:30px; text-align:center; background-color:#6d8cbf"> TEXT </span></td> Unfort ...

What is the method for rotating a map using JavaScript?

My map built with Leaflet displays a route and a moving car marker. Now, I am looking to implement a feature where the map rotates based on the direction of the car. I have access to both the current coordinates of the car and the target coordinates. ...

Revamp the HTML table with JavaScript headers

I imported data from a CSV file into an HTML table and here is how it appears: <div id="myTable" style="-ms-overflow-x: auto;"> <table> <tbody> <tr class="rownum-0"> <td>Make</td> ...

Creating effective href anchors within an iframe using the `srcdoc` attribute

While loading some HTML content in an iframe using the srcdoc attribute, I encountered an issue where following anchor tag links inside the iframe caused the entire page to load within the iframe instead of scrolling to the linked id. You can see a demons ...

The battle between Hover, Focus, and Blur modes intensifies

My goal is to implement 4 different effects on an element: When hovering over the element. When moving away from the element. When focusing on the element. When blurred. However, I'm encountering a conflict where when I focus on the element, the ...