Grid element content suddenly shifts when opened

I am facing a peculiar issue with my layout. When I specify grid-template-rows: 1fr 1fr and try to open the details element, instead of smoothly expanding downwards, it seems to "jump" into position. This odd behavior disappears when I use grid-template-rows: auto. However, if I do need to explicitly set the rows, how can I prevent this jumpy effect and ensure that the element opens normally?

main {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 2px 2px;
  align-items: stretch;
  justify-content: stretch;
  grid-auto-flow: row;
  justify-content: stretch;
}
<main>
  <p>Paragraph 1.</p>
  <details>
    <summary>Jumpy summary</summary>
    <ul>
      <li>Line 1.</li>
      <li>Line 2.</li>
      <li>Line 3.</li>
      <li>Line 4.</li>
      <li>Line 5.</li>
      <li>Line 6.</li>
      <li>Line 7.</li>
      <li>Line 8.</li>
      <li>Line 9.</li>
      <li>Line 10.</li>
    </ul>
  </details>
</main>

Answer №1

Setting two rows to equal height with grid-template-rows: 1fr 1fr creates a specific layout.

The height of the "Jumpy summary" section is initially equal to the Paragraph item when collapsed.

However, upon expanding the section, the Paragraph item adjusts its height to match its sibling, causing the Jumpy summary to shift down the screen.

To address this behavior, consider using grid-template-rows: auto auto instead.

For more detailed information on this topic, refer to the explanation provided in this link: Equal height rows in CSS Grid Layout

main {
  display: grid;
  grid-template-rows: auto auto;
  gap: 2px 2px;
  align-items: stretch;
  justify-content: stretch;
  grid-auto-flow: row;
  justify-content: stretch;
}
<main>
  <p>Paragraph 1.</p>
  <details>
    <summary>Jumpy summary</summary>
    <ul>
      <li>Line 1.</li>
      <li>Line 2.</li>
      <li>Line 3.</li>
      <li>Line 4.</li>
      <li>Line 5.</li>
      <li>Line 6.</li>
      <li>Line 7.</li>
      <li>Line 8.</li>
      <li>Line 9.</li>
      <li>Line 10.</li>
    </ul>
  </details>
</main>

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

What is the reason for background images not loading when using `display: none`?

I'm really struggling to understand this puzzle: When the page loads, will mypic.jpg be downloaded by the browser? #test1 { display: none; } #test2 { background-image: url('http://www.dumpaday.com/wp-content/uploads/2017/01/random-pic ...

JS: Initiating a new keypress operation

When I press the Tab key, I want it to do something different instead of its default action. Specifically, I have a text box selected and I would like it to add spaces (essentially making the textarea behave like a text editor). How can I trigger this type ...

Materialize.css | managing spaces, indentation, and 'overriding' in a span element

I recently started using a new framework called Materialize CSS for my project and I'm still getting the hang of it. One issue I've encountered is that long texts in my sidebar are creating large spaces between line breaks and strange indents. D ...

Issue with deploying responsive background image on Github platform

My responsive background image isn't displaying properly on mobile devices after I deployed my project to Github. Although it appears correctly under the Google Chrome inspect mobile tool, when accessed live on a mobile device, the image covers the ba ...

Wheel of fortune - The chosen option does not align with the indicator

I am looking to create a game similar to a "Spinning Wheel" where users can select three possible outcomes and then spin the wheel. If any of the chosen three options appears when the wheel stops, the user wins. In the demo provided below, you may notice ...

Update the appearance of buttons using AngularJS

I am trying to change the style of 3 buttons when they are clicked. I am not sure if angular has built-in functions like ng-class or ng-click that can help me achieve this. I have tried implementing them but it doesn't seem to work. <button class= ...

React state update not triggering a component re-render

I've been attempting to toggle the visibility of a div by clicking on another div, but I'm encountering an issue. The div becomes invisible on the first click only if it was visible initially. After that, it remains invisible and does not update. ...

How can I make two flexbox items in a row stack on top of each other as a column?

I'm currently working on a layout that involves a parent flexbox containing multiple sections. My challenge lies in getting two specific sections to stack vertically while the rest of the layout remains horizontal. At the moment, I have two sections ...

Experience a captivating Bootstrap 4 drop menu animation that emerges from beyond the borders of the page

I have a row that contains two divs, one with col-md-11 and the other with col-md-1. Inside the col-md-1 div, there is a dropdown that I want to animate. I am using animate css for the animation, but the issue is that the slideInRight animation starts from ...

Angular JS is having some issues with rendering the style correctly

How can I make input fields turn pink before values are entered and green after values are entered? Currently, the styling only applies to the first row. What could be causing this issue? <script src="https://ajax.googleapis.com/ajax/libs/angularjs ...

Html elements remain stationary and do not shift positions

I am attempting to customize a web page by repositioning an input text element. Below is the code I'm using: <body> <h1>Shopping List</h1> <input id="search" type="search"> <input id='newItem' type="t ...

Tips for including a horizontal line beneath each heading in an HTML using just CSS

Is it possible to include a horizontal line following each heading without employing the <hr> tag? I am interested in accomplishing this solely within the parameters of the <style></style> tags. ...

Troubleshooting a Navigation Tab Problem in Bootstrap 4

Hi, I am new to using bootstrap. Can anyone help me figure out how to achieve the look in the image using bootstrap-04? I want this design to be consistent across all devices, but I am having trouble implementing it. Any guidance is appreciated. Thank you ...

Preserve menu settings by utilizing local storage

I have been working on saving the state of my menu using localstorage. The jQuery code below is what I am currently using to toggle my menu: <nav id="sidebar" class="active"> <ul class="menu"> <li> <a href="#">Customer ...

Error: The function replace cannot be used on elem

Here is what I am attempting to achieve: for loop inside the append is not working Below is my code: $('body').append( $('<section>').append( $('<form>') .attr('class', "ac-custom a ...

The toggle buttons in Bootstrap are not functioning as expected despite adhering to the recommended

I have been using Bootstrap 4 and I recently tried to create a toggle button group following the official documentation. Here's the code I used: <div class="btn-group btn-group-toggle" data-toggle="buttons"> <label class="btn btn-secondary ...

Secure Social Security Number (SSN) Input Field showing only the final four digits | includes option to show/hide

I need to show only the last four digits of the SSN and mask the rest with asterisks, like: ****-**-7654 Additionally, I want to implement a toggle functionality where users can reveal or hide the masked characters behind the asterisks. <in ...

What makes the <aside> tag in HTML a sectioning content, while the <main> tag is not?

I've been delving into the HTML specifications provided by whatwg and MDN. They outline the 4 sectioning elements: article, aside, nav, and section, and mention that they establish the scope of footers and headers. Now, I have a couple of queries: ...

Creating an animated link with a dynamic underline featuring a trio of vibrant colors

I'm having trouble figuring out how to animate my links on hover with 3 different colors. I attempted using the linear-gradient property but it doesn't seem to be working. Any suggestions on how to proceed? Below is an example of what I'm a ...

Verify that the text entered in the form is accurate, and if it meets the required criteria, proceed to the next

Is it possible to achieve this without using JavaScript? If not, I'd like to find the simplest solution. I have a form that functions similar to a password entry field, and I would like to redirect users to a certain page if they type in a specific p ...