CSS grid: guarantee that all dynamic rows maintain a uniform size throughout

I'm facing a unique scenario here. I'm attempting to utilize CSS grid to display content side by side. The challenge is that one side of the content needs to have dynamic height while the other side should remain fixed.

Here's an example:

.page {
  display: grid;
  grid-template-columns: repeat(4, 25%);
  grid-template-rows: repeat(5, 16px);
  grid-auto-rows: fit-content(16px);
  border: 1px solid blue;
}

.text {
  grid-row-start: 1;
  grid-row-end: auto;
  grid-column-start: 1;
  grid-column-end: 4;
  border: 2px solid red;
  display: flex;
}

.description {
  grid-column-start: 4;
  grid-column-end: 5;
  grid-row-start: 1;
  grid-row-end: 5;
  border: 1px solid green;
  display: flex;
}
<div class="page">
<div class="text">
  Nam adipiscing. Aenean viverra rhoncus pede. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. Donec posuere vulputate arcu. Fusce egestas elit eget lorem.

Quisque rutrum. In consectetuer turpis ut velit. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Nullam dictum felis eu pede mollis pretium. Maecenas egestas arcu quis ligula mattis placerat.

Fusce pharetra convallis urna. Curabitur suscipit suscipit tellus. Vestibulum volutpat pretium libero. Donec mi odio,...

Fusce pharetra convallis urna. Cur...
</div>
<div class="description">
   <img src="https://www.clker.com/cliparts/y/c/r/G/g/M/warning-md.png" alt='Warning clip art' style="height: 100%;" />
</div>
</div>

The goal here is to have content in 4 columns, each with 25% width, and 5 rows with fixed height (16px each), represented by the blue area. As the text content might vary (in the red area), I'd like it to expand into more rows if needed without affecting the image (green area).

I've experimented with auto rows but encountered the issue of the image stretching along with the text due to automatic row height. I'm uncertain if achieving this layout is feasible using only grid.

Answer №1

Ensure the image height is fixed and avoid defining any row configuration:

.page {
  display: grid;
  grid-template-columns: repeat(4, 25%);
  border: 1px solid blue;
}

.text {
  grid-column: span 3;
  border: 2px solid red;
}

.description {
  border: 1px solid green;
  display: flex;
  height: 80px;
}
<div class="page">
<div class="text">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  
Nulla facilisi. Aenean nec eros et neque tristique congue non at orci. Fusce ac massa tincidunt, interdum quam vel, tincidunt ipsum. Curabitur blandit sapien nec rutrum interdum. Mauris auctor justo eget dui pellentesque pretium.

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed efficitur imperdiet diam ut cursus. Nullam sit amet feugiat felis. Vivamus erat mauris, porttitor a nunc sed, ultrices vestibulum odio.
</div>
<div class="description">
   <img src="https://www.example.com/image.jpg" alt='Image' style="height: 100%;" />
</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

The website's text content loads first, allowing for images to take their time and load afterwards

My priority is to ensure that my images load as quickly as HTML and CSS. Currently, the loading time for images (all in .svg format and small) exceeds 2 seconds after other content loads, despite HTML and CSS loading swiftly. Is there a method to expedite ...

Shine a spotlight on elements that match with jQuery using live() or on()

Check out my jsFiddle demonstration where I have created a button that adds elements and provides links to delete these elements. Instead of actually deleting the elements in this example, I want to make it so that hovering over the (remove) link, which is ...

Is there a way to automatically recalculate the "Total Price" when the input values are adjusted?

Whenever I add an item to the cart, it gets appended to the row in the shopping cart, and the price adjusts accordingly. However, I'm having trouble getting the price to adjust whenever I change the input values (input type: "number"). I can't se ...

Prevent drag and drop functionality in QtWebkit

As I work on creating an HTML GUI for my application using Qt's WebKit, everything is going smoothly with one minor issue. I am trying to prevent users from dragging and dropping images from the GUI itself. While I have successfully disabled text sele ...

How can I load a URL without causing a page refresh?

While searching around, I stumbled upon this HTML 5 code snippet: window.history.pushState("object or string", "Title", "/new-url"); I started thinking: how can this be implemented? Is there a way to utilize this code to change the URL to without needin ...

The method .slideUp() is not functioning as intended

My current project involves a page structure that looks like this: <div id="wrapper"> <div id="page_banner"> <canvas id="voucher_canvas"></canvas> <div id="div_voucher_img"><img id="voucher_img" src="" ...

I'm currently attempting to determine the total cost of a series of operations, however, I am not receiving any results

Here is the code snippet from my HTML file: <tr> <td><input id="z1" type="number" oninput="calculateSubTotal()"> </td> <td>Shirts - WASH - Qty 1 to 4</td> <td>2.50 ea</td> ...

CSS: Overlapping pop-up obscuring another element

I am having an issue with my pop-up appearing behind another control, specifically an auto-complete text box. <div id="navTarget"> <ul class="menuTarget"> <li><a href="#"&g ...

Retrieve the border color using Selenium WebDriver

Hey everyone, I'm currently trying to retrieve the border color of an extjs 4.2 form control text field using the getCssValue method. However, I'm having trouble getting the value as it's coming back blank. Below is a sample of my code that ...

A different way to center elements using CSS

Many criticize the center tag, but I find that it consistently aligns things perfectly for me. Despite its deprecation, I still rely on it. I've come across suggestions to use the mysterious CSS margin: 0 auto;, but I struggle to make it work (refer ...

Tips for conducting a simulated XSS attack on the login page

Login Page <html> <head> <title> Login </title> </head> <style> #footer { position:absolute; bottom:0; width:100%; height:60px; } </style> <body> <div class="container"> <form me ...

Trouble aligning a div at the center within another div using margin auto

I am facing an issue with centering a div horizontally inside another div. Here is my HTML code: .block { padding: 0px 20px; max-width: 820px; margin: 0 auto; background-color: #ff0; } .container { margin: 0 auto; display: inline-block; bac ...

Challenge encountered when trying to store AngularJS response in a global variable

When making an HTTP call to the controller using angular.js, I am trying to save the response in a global variable like so: app.controller('dashBoardController', ['$scope', '$http', '$location', function ($scope ...

Tips for postponing an action until the webpage is fully loaded

Currently, I am using Selenium in R to perform a specific task. The script I have written enables the program to search for pizza restaurants near a designated geographical coordinate on Google Maps. The script continues to scroll until all restaurant inf ...

Guide on embedding internet audio onto an HTML webpage

I'm currently working on adding sounds and music to my program. The code that I have works perfectly when the audio files are downloaded onto my computer. However, I am looking for a way to play these sounds directly from the internet without needing ...

What is the best way to showcase an image using CSS on my personal computer?

It's a bit embarrassing to admit, but I'm learning some new concepts and struggling with this one. On my computer, there's a folder named Test that contains an index.html file, a CSS subfolder with an index.css file, and an images subfolder ...

Unable to access or click on Wordpress links or site titles

On my website, www.website.com, I have a main Wordpress installation and a test site at www.website.com/test. The main site functions correctly, but the links on the test site are behaving strangely. I have set the post title as the permalink structure (w ...

Optimizing User Addition in Python Using Selenium

Currently, I am developing test cases to populate a new web app account with multiple users simultaneously. Here is the script I am using: driver.find_element_by_css_selector("input.ss-med.small").clear() driver.find_element_by_css_selector("input ...

What causes certain content to be inaccessible when using Safari?

When I visit this page using Safari or my iPhone, the list of social network members does not appear. Can anyone explain why this might be happening? I am unable to figure out the reason behind this issue. Thank you in advance for your help! ...

I am attempting to create a stylish border for the .navbar-collapse element, but unfortunately, my efforts have been unsuccessful so far

I need assistance with adding a border around my mobile drop-down menu. I've tried using .navbar-collapse but it's not working. Any suggestions? Here is a sample image of the mobile size: https://i.sstatic.net/O9oA1.png Below is my code: < ...