When I provide three values for grid-auto-rows, will CSS generate three rows accordingly?

Let's consider the following CSS property:

div {
    display: grid
    grid-auto-rows: 15% 70% 15%;
}

Does this imply that within the container, there will be three rows where each row occupies a percentage of the parent container's height?

Answer №1

Indeed, grid-auto-rows dictates the height of implicit rows, which are generated by the grid to accommodate items that fall outside the boundaries of the explicit grid. Unlike grid-template-rows, grid-auto-rows does not automatically form rows.

https://www.w3.org/TR/css3-grid-layout/#implicit-grids


Yes, your grid-template-rows rule will establish a grid with three explicit rows.

No, the percentage values in grid-template-rows are not relative to the parent's height. They are tied to the height of the same element (the grid container).

You can experiment with this setup here: https://jsfiddle.net/2cxw0Lrn/

/* body { height: 100vh; } */

article {
  display: grid;
  grid-auto-rows: 15% 70% 15%;
  grid-gap: 5px;
  height: 100vh; /* disable and try body height above */
  background-color: gray;
}

section { background-color: lightgreen; }
body    { margin: 0; }
<article>
  <section></section>
  <section></section>
  <section></section>
  <section></section>
  <section></section>
  <section></section>
  <section></section>
</article>

This behavior is outlined in the specification:

7.2. Explicit Track Sizing: the grid-template-rows and grid-template-columns properties

<length-percentage>

<percentage> values are relative to the inline size of the grid container in column grid tracks, and the block size of the grid container in row grid tracks.

Referencing the spec will clarify terms like "inline" and "block" size, but the primary idea remains: the values are proportional to the grid container.

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

Error with Display of ASCII Character 62 in Superfish Menu

Currently, I have implemented the Superfish menu on my website. In order to indicate sub-menus within my menus, I have opted to utilize the character entity code &#62;, which historically has represented ">". Oddly enough, while viewing my website ...

Selecting a date in a pop-up

In my PHP application, I have incorporated a date selection feature within a modal dialog. However, when clicking the control, the calendar appears in the left corner of the page and remains visible even after selecting a date. Additionally, clicking elsew ...

What causes the element with position: fixed and width 100% to exceed the viewport boundaries on iOS 8?

I'm facing an issue with an element that is fixed to the top of the page and scrolls horizontally along with the page. The CSS code for this element is quite straightforward: .thing { position: fixed; top: 0; width: 100%; height: 30px; back ...

Conceal a Drawer Beneath a Curved Header Using Material UI and Custom CSS Sty

I am facing a challenge with my menu that needs to be concealed behind an arch design. https://i.sstatic.net/CwdjJ.png The objective is for the menu to appear hidden behind the black area, while still being visible over the blue arch in the background (a ...

When the li is clicked, replicate it and display it in a separate div

When a list item is clicked, I want to clone it and display it in a separate div. If another list item is clicked, the previously displayed item should be replaced with the newly clicked one. Below is my code along with a link to the codepen where you can ...

Responsive SVG curve line design

Trying to position the SVG line in the center with the SVG icon, without overlapping them. Need a responsive solution that adapts to the container width. Any suggestions involving canvas or after pseudo classes? The line and icon should always be centere ...

Is there a way to adjust the size of the canvas element in HTML without compromising quality or resorting to zooming?

I'm currently working on a basic modeling application for the web. The main component of my app is a canvas element that I'm trying to size correctly. However, when I set the height and width using CSS, it scales the entire canvas and compromises ...

Adjusting the inner div dimensions to be 100% of the body's size without relying on the parent div using JavaScript

I have a main layer with multiple layers stacked on top of it. I need the second layer to extend its width to match the body's width. Main Project: http://example.com What I've tried: I looked into: Solution for matching div width with body ...

Tips for customizing the appearance of popup windows

I want to enhance the appearance of my popup window by applying a different format for opening it. How can I style it so that it looks visually appealing when the popup window opens? You can find below the source code I am working with: HTML: <div onM ...

Aligning Checkbox Labels for Web Forms

Can an image convey more than a thousand words? I'm looking to align the second (and following) lines with the first one. Any suggestions? Html stands for <input><span>text</span> ...

Maximized - Immersive Full Screen Background - Limited to Half the Size?

Looking to incorporate the Supersized Fullscreen background found at Supersized Interested in having the slider appear on the right half of the site with content on the left half. Want the content to move when scrolled while keeping the background station ...

JavaScript is having trouble properly concealing or revealing elements on the webpage

I am currently designing a web form for my wife, who works at an insurance agency. She needs a web-based form to collect information for processing insurance quotes. Without access to a server, I need to ensure that all the details inputted by the user can ...

Can you explain the distinction between [att|=val] and [att~=val] in css?

Could someone help me differentiate between the [att|=val] and [att~=val] attributes in CSS? I'm having trouble grasping the concept. Thank you! ...

Using a color as a substitute for a background image on mobile devices

Is there a way to create a fallback in my CSS for changing the background image to a color when viewed on a mobile browser once the pixels reach the max-width? In the snippet below, the media query "only screen and (max-width: 600px)" works if the top bod ...

Tips for delivering a variable to a React Native Stylesheet

Is there a way to pass a variable to the "shadowColor" property in my stylesheet from an array declared in the code above? I keep encountering a "Can't find name" error. Attempting to use a template literal has not resolved the issue. Any assistance w ...

Efficient Techniques to Eliminate Unwanted Jumping in CSS Transitions

I am currently working on a unique "stack" component that is inspired by the amazing ElastiStack. You can check out a cool demo of my work here. The demo works flawlessly on desktop Chrome, but unfortunately, I have encountered some issues with the transit ...

Adjust the default dimensions of the background image

My CSS file includes the following code: input.myInput { background-image:url('search.png'); background-size:120px 120px; } In my HTML file, I have the following input element: <input type='text' class='myInput' > I ...

Displaying a Bootstrap button and an input box next to each other

Looking for advice on aligning or arranging a button and input box side by side in Bootstrap without grouping. I've searched online for examples, but they all involve grouping of elements. jsfiddle: https://jsfiddle.net/erama035/p9dagmL3/3/ <div ...

Button placed incorrectly

I am utilizing bootstrap 4, thymeleaf, and datatable I attempted to place a button on top of the table to the right <div class="col-sm-12"> <div class="float-right"> <button id="newUsers" type="button" th:onclick="@{/newusers ...

Avoid replacing CSS properties, instead use jQuery to supplement them

Can anyone help me figure out how to use the jquery .css() function without overwriting existing values, but instead adding additional values to css properties? For example, I have an element that currently has the css transform:translate(-50%, -50%). I w ...