What causes elements to move downward when the grid container is rotated?

I noticed a strange anomaly in CSS. In short, when I hover over a rotated div, the contents inside the div seem to shift down by about 1 pixel. This only seems to occur at specific view heights.

Take a look at this gif demonstrating the issue (pay attention to how the text "One" shifts about one pixel):

https://i.sstatic.net/jeA6p.gif

Here is the most minimal example I could create:

.header {
  background-color: orange;
    height: 30vh;
}
.container {
  display: grid;
  height: 100px;
  width: 100px;
  border: 1px solid red;
}

.front {
  grid-area: 1/1;
  background-color: blue;
}

.back {
  grid-area: 1/1;
  background-color: red;
  transform: rotateY(180deg);
}

.back,
.front {
  backface-visibility: hidden;
  transition: transform 1s;
  margin: 1rem;
}

.container:hover .back {
  transform: rotateY(0deg);
}

.container:hover .front {
  transform: rotateY(180deg);
}
<div class="header"> HEADER </div>
<div class="container">
  <div class="front">
    <h2>One</h2>
  </div>
  <div class="back">Two</div>
</div>

You can also find the same code on Codepen if resizing it here is difficult: Codepen showing issue

The issue doesn't manifest at all screen heights, so open DevTools and gradually decrease the screen height, testing the hover at each interval. The shifting occurs during rotation at certain heights, negatively impacting any card flip animations.

Answer №1

Only occurring on a limited browser height.

To prevent the jumping, consider changing vh to px within the .header section.

To address this issue, you may want to include an @media query targeting smaller screen heights with vh for larger screens.

@media screen and (max-height: 160px) {
    .header {
        height: 50px;
    }
}

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

Explore the functions of jQuery's .css() method and the implementation of

Could use some assistance with the .css() method in jQuery. Currently working on a mouseover css menu, and encountering an issue when trying to include this code: $(this).siblings().css({backgroundColor:"#eee"}); at the end of my script. It seems to int ...

Dynamic table that collapses/expands in Python's Flask framework

I am currently working on developing a table in Flask with collapsible rows. I have encountered an issue where, while hardcoding values works perfectly, populating the table using a loop with data from a Python dictionary results in only the first child of ...

What is the best way to conceal an unordered list menu?

Trying to create a menu using ul HTML, but encountering an issue. When the website is opened, the menu shows up by default, whereas I only want it to appear when a mouse hovers over it. Even after attempting to change the CSS class, the desired functionali ...

Ensuring Bootstrap 4 columns have identical height to their siblings when large amounts of scrollable content are present

Is there a way to set the height of a column to match its sibling? I need the children of a column to have a specific height that fills up the remaining space, even if their content is too large. Check out this demo for reference: https://stackblitz.com/ ...

Switching the sorting criteria from 'AND' to 'OR' in the JPList library

I am currently exploring the use of JPList to sort on multiple items. As it stands, JPList searches like 'AND' when sorting (e.g. sorting based on an item with tags html, php and jQuery all together), but I am interested in filtering through all ...

When you zoom in or out, HTML5 elements styled with CSS will dynamically adjust

Hey everyone, I have a question about a problem I'm facing with my HTML and CSS page. The issue is that when I zoom in, the "Section" part moves underneath the nav bar, and when I zoom out, the footer moves next to the section part... Below is a sni ...

Slider caption glitching out

I am encountering an issue with the caption I added to my slider. When I scale the page, the height becomes inconsistent. It seems like the caption is not in an absolute position on the page. Strangely, when I try to position it absolutely, it disappears? ...

What is the best method for selecting an Iframe in Firefox using HTML?

As a student working on building a website, I recently added some iframes to a WordPress page and noticed that all links were opening in new tabs specifically in Firefox. The HTML code in question: <a href="http://example" target="exampl ...

How does the browser interpret the CSS property transform: none?

Does the transform: none result in matrix(1,0,0,1,0,0) or a different outcome? I am looking to reset the transform; what is the best approach for this? <style> .box{ height: 100px; width: 100px; background-color: red; transition: 0.5s; transform: ...

Searching for a comprehensive guide to web-related terminology that is widely accepted

Constantly immersing myself in studying the languages I am familiar with and exploring new development concepts and languages is a regular practice for me. When it comes to books, O'Reilly is my go-to choice, but when it comes to online resources, I&a ...

Guide on using JavaScript to implement the universal CSS selector

One technique I frequently employ is using the CSS universal selector to reset the dimensions in my HTML document: * { border: 0; margin: 0; padding: 0; } I wonder if a similar approach can be achieved with JavaScript as well? When it come ...

Why isn't the z-index functioning properly in Vue.js styling?

I am currently developing a simple component that displays four steps, indicating the current step and allowing users to navigate through them. I want to create a design where these numbers are enclosed within circles that are evenly distributed in a line ...

What is causing the extra space on the right side of the box?

I've been struggling to align text next to an image inside a box. Desired outcome CSS: #roundedBox { border-radius: 25px; background: #363636; width: auto; height: auto; margin: 10%; display: flex; position: relative; ...

ajax fails to send the variables, instead sending undefined values

In my HTML code, I have inputs and checkboxes. The JavaScript code collects the data from the inputs, and through AJAX, it should send the information to PHP where it is received and stored in the session. However, when sending the array to the PHP file v ...

Arrange the table in alphabetical order and categorize it

Hello there! I am currently working on creating a well-organized table list where names are sorted into specific categories based on their starting letter. For example, names beginning with 'A' will be placed in the 'A category', while ...

Is there a way to incorporate both duration and easing effects when using slideToggle()?

I am currently working on a sliding menu with jQuery and the bounce jQuery UI effect. The issue I am encountering is that the hover event does not trigger when I hover over the first li element. Here is the snippet of my JavaScript code: $(document).ready ...

Convert Jupyter notebook to an executable html file

Looking for a way to export a Jupyter notebook in HTML to get an executable version? Currently, I upload the notebook to a git repository and use binder to obtain its executable form. However, I want to directly upload the notebook to my website without ha ...

How to select a button within a table using Selenium and C#?

I'm struggling with a section of HTML code. My goal is to use the selenium chrome driver in C# to navigate a website and create a ticket. However, I've encountered an issue where I need to select a tab to check some checkboxes, but all the tabs h ...

Turn off HTML display for Internet Explorer users

I am looking to implement code that will block certain pages for Internet Explorer users, making it accessible only for Google Chrome and Firefox users. Do you have any suggestions on how I can achieve this or if there are existing solutions available? I& ...

What is the best way to position two text fields next to each other on a webpage?

As I design a form for a landing page, my goal is to arrange the text input fields side by side in order to avoid making the form too lengthy. I am striving to achieve a layout similar to this: https://i.sstatic.net/PTCr4.png However, the task seems quit ...