Minimize the gaps between items within a CSS grid design

I'm struggling with adjusting the whitespace between 'Job Role' and 'Company Name' in my grid layout. Here's a snippet of what I have:

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

The container css is set up like this:

.experience-child {
    display: grid;
    grid-template-columns: 2fr 6fr;
    grid-template-rows: repeat(5, 1fr);
    margin-bottom: 6em;
    font-family: 'Alumni Sans', sans-serif;
}

I've tried various methods including adjusting row-gap, margin, padding, and adding grid-auto-rows to the container but haven't been successful.

Here's the HTML & CSS for replication:

<div class="experience-child">
    <p class="years">2001-2001</p>
    <p class="jobrole">Job Role</p>
    <p class="company">Company Name</p>
    <ul class="job-blurb">
        <li>this</li>
        <li>that</li>
        <li>other</li>
    </ul>
</div>
.experience-child {
    display: grid;
    grid-template-columns: 2fr 6fr;
    grid-template-rows: repeat(5, 1fr);
    margin-bottom: 6em;
    font-family: 'Alumni Sans', sans-serif;
}

.last {
    margin-bottom: 0;
}

.jobrole {
    font-weight: bold;
}

.company {
    grid-area: 2 / 2 / 3 / 3;
    font-weight: bold;
}

.job-blurb {
    grid-area: 3 / 2 / 5 / 3;
}

Answer №1

grid-template-rows: repeat(6, 1fr);
means that your grid consists of 6 rows with equal height. This corresponds to the total height of the .project-item container divided by 6.

There are various ways to minimize the space between Title and Description:

  • You can decrease the height of the first row by changing it to something like

    grid-template-rows: 2em repeat(5, 1fr);

  • You can maintain uniform row height and reposition Title within its container using methods such as position: absolute; bottom: 0;, or padding-top: 2em;

  • You can place Description in the same container as Title by enclosing

    <p class="title">Title</p><p class="description">Description</p>
    in a new div

Answer №2

Update

grid-template-rows: repeat(5, 1fr);
to
grid-template-rows: repeat(1, 1fr);
.

Take a look at the code snippet provided below.

.experience-child {
  display: grid;
  grid-template-columns: 2fr 6fr;
  grid-template-rows: repeat(1, 1fr);
  margin-bottom: 6em;
  font-family: 'Alumni Sans', sans-serif;
  background-color: gold;
}

.last {
  margin-bottom: 0;
}

.jobrole {
  font-weight: bold;
}

.company {
  grid-area: 2 / 2 / 3 / 3;
  font-weight: bold;
}

.job-blurb {
  grid-area: 3 / 2 / 5 / 3;
}

p {
  margin: 0;
}
<div class="experience-child">
  <p class="years">2001-2001</p>
  <p class="jobrole">Job Role</p>
  <p class="company">Company Name</p>
  <ul class="job-blurb">
    <li>this</li>
    <li>that</li>
    <li>other</li>
  </ul>
</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

Initiating a click function for hyperlink navigation

Here is the HTML and JavaScript code that I am currently working with: <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-3.3.1.min.js"></script> </head> <body> <a href="#f ...

What could be causing the malfunction of this form's submission request?

I'm encountering an issue with a simple login form I have that I want to post to ASP.Net MVC. It seems like when I set the action to /Login, it works perfectly fine. However, if I specify the action name as "/Login/Index", it fails. The server sends b ...

Positioning a box at the bottom rather than at the top

I am on the lookout for a solution to shift/arrange divs to the bottom instead of the top. For example, when attempting to delete some of the divs with the "box" class in this code snippet: Current code: #hol ...

Navigate post Ajax call

When I make an unauthenticated GET request using AJAX, my server is supposed to redirect my application. However, when I receive the redirect (a 303 with /login.html as the location), the response tab in the Firebug console shows me the full HTML of the lo ...

Utilizing JavaScript to dynamically resize an element within a slide as soon as the slider transitions to the following slide

RESOLVED! ISSUE FIXED! While working on my personal website using WordPress and the Smart Slider 3 plugin, I encountered a problem with the positioning and size of an element in the second slide. Despite finding a tutorial explaining how to manually trigg ...

Give GetElementsByClassName a shot

Hey, have you tried using js ref_doc_getelementsbyClassName? "I keep getting the error message 'Uncaught TypeError: Cannot set property 'value' of null' " Check out this HTML code snippet: <input type="text" cla ...

Tips for updating the value of an input text field in one HTML table according to a certain value entered in a different input text field located in another HTML table

I am working with an HTML table that consists of one row. Within this row, there are two TDs which each hold their own tables (each containing 10 rows with 10 input fields). My goal is to update the value of another corresponding text field based on change ...

Assist the floats to "ascend" and occupy the available space

The screenshot showcases boxes that have been styled with "float: left". Is there a way to make these boxes float to the first available space in a column? For example, can we move the Music Nation box to the location indicated by the red arrow in the ima ...

Determine the output by applying a constant value to the input

I'm having an issue with a loop function. The goal of the code is to allow users to enter a quantity of goods they want to buy, and then JavaScript calculates a fixed value based on the chosen quantity, which should be printed out. This functionality ...

Could the reason behind the malfunctioning of the bootstrap tabs be due to my CSS files?

I'm looking to implement Bootstrap tabs in the sidebar of my website, but I'm running into an issue where the tabs aren't functioning properly within the sidebar-parsel-liste class. If I place the tab tags outside of this class, everything w ...

Adding an image to an HTML <span> element using the class attribute "

I need help adding an image to my HTML code. For example, how can I specify which image should be displayed in place of the placeholders? Thank you for your assistance! ...

Adjust the message hues upon form submission with Ajax

Can anyone provide assistance? I am in need of a functional form for sending emails. <form enctype="multipart/form-data" role="form" id="form" method="post" action="handler.php"> <div class="form-row"> <div class="form-g ...

Activate all inactive input and selection elements

I need a solution to enable all disabled input and select elements before submitting the form in order to retrieve the values of those disabled elements. Here is what I have tried: function enable() { $('input[type="text"], input[type="chec ...

CSS ISSUE: Issue with hidden overflow causing white space next to border in nested divs

When working with a div inside another div and setting overflow to hidden, you may notice a whitespace issue around the border when zooming in and out on Chrome. Firefox handles this situation better, showing white space only in the corners of the border. ...

Using flex and align properties to position two elements on the right and one on the left is a common layout challenge

I'm facing an issue with element positioning and text alignment. The navigation container consists of three elements: logo, title, and nav-list. You can find the code on CodePen. /**{ margin: 0; padding: 0; box-sizing: ...

Utilize drag and drop functionality to interact with an HTML object element

I am struggling with a div that contains a PDF object and draggable text: <html> <head> <script> function allowDrop(ev) { ev.preventDefault(); } function drop(ev) { alert("DROP"); } </script> </head> <body> <di ...

What is the best way to customize my menu so that the currently selected element stands out with a distinct color?

I'm struggling with customizing the background color of the active page due to complex HTML structure. I'm using responsive twitter bootstrap (2) and facing challenges. To view all tabs at the top, you need to stretch the viewing window. Below is ...

Is there a way to connect two tables using CSS pseudo-selectors?

Is there a way to make two separate tables interact with each other using CSS pseudo-selectors? I have a data table and an auto-numbered table, and I want the rows to highlight in both tables when hovering over a cell in one of them. I've tried using ...

Creating a dynamic pulse effect using jQuery to manipulate CSS box-shadow

My goal is to create a pulsating effect using CSS box-shadow through jQuery. Despite my best efforts, the code I attempted failed to produce the desired smooth pulse effect with box-shadow. The code snippet I experimented with: <div class="one"> &l ...

Mpdf does not support inline CSS rendering

I recently implemented Mpdf into my Symfony project using Composer. The installation process involved running the following command: composer require mpdf/mpdf Next, I included the Mpdf.php file in autoload.php. Here is an example of how to use Mpdf in ...