Why do elements nudge down upon rotation, in grid container - html

I stumbled across an oddity in CSS. Briefly told, when rotating a div upon hover, the contents within the div nudges down what looks like 1 pixel or so. It only happens at certain view heights.
Here is a gif that shows the issue (notice how the text "One" nudges about one pixel):
Here is the smallest reproduction I was able to make:
.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>
A Codepen with the same code, in case the above is hard to resize: Codepen showing issue
The problem does not occur on all screen heights, so activate DevTools then shrink the height of the screen gradually, trying a hover at each height. It will nudge upon rotation at certain heights. The nudge causes any card flip animation to look bad.

It indeed only happens on small browser height.
It works without jumping if you change vh to px in .header.
In you case, I would add #media query for screens with small height and vh for bigger screens.
#media screen and (max-height: 160px) {
.header {
height: 50px;
}
}

Related

How to cover all space with background image during parallax scroll? [CSS only]

I am trying to build a CSS-only parallax background, which moves at a different speed than its text content. So far everything works except that I can't get the background to stretch/position so that it won't run out of space when the page is scrolled to its bottom.
I've created a snippet for you, which shows a grid background (png). I can change the size of the grid png but no matter what I try, the grid-free space at the bottom won't go away. I've tried playing around with margins and paddings, scaling the different parallax elements and changing the perspective/translateZ():
.parent-container {
background-color: #15152a;
}
.parallax-container {
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
perspective: 2px;
}
.parallax-layer {
transform-style: preserve-3d;
}
.parallax-layer::after {
position: absolute;
content: '';
inset: 0;
transform: translateZ(-2px) scale(2);
background: url('https://i.postimg.cc/138FbqVX/grid.png');
background-size: 100%;
z-index: -1;
height: 100vh;
}
.content {
padding: 50vh 16% 10vh 27%;
color: white;
font-size: 4rem;
}
<div class="parent-container">
<div class="parallax-container">
<div class="parallax-layer">
<div class="content">
hello world
</div>
</div>
</div>
</div>
I want to get rid of the bottom part of the page, which has no grid.

CSS - why top element always remains on top while rotating 180deg?

I have a container with two elements absolutely positioned. While rotating the container on hover, why the top elements always remains on top even when the container is rotated by 180deg. why don't we see the bottom element then?
body {
perspective: 1000px;
}
.container {
margin: 20px 0 0 20px;
position: relative;
height: 400px;
width: 250px;
transition: all 3s;
}
.container:hover {
transform: rotateY(180deg);
}
.item {
position: absolute;
height: 100%;
width: 100%;
}
.item-1 {
height: 120%;
background: orange;
/* z-index: -1; */
}
.item-2 {
background: cyan;
/* z-index: 1; */
}
<div class="container">
<div class=" item item-1"></div>
<div class=" item item-2">Hover Over Me!</div>
</div>
code: https://jsfiddle.net/rj5b9dhc/
I have the solution, but I'm curious why above code doesn't work
solution code: https://jsfiddle.net/512p9x3r/1/
Because of backface-visibility: hidden; in item-2 css in solution code.
Check this: w3schools
Updated:
When .item (two items) height is 100%, .item-2 have no height in it css and covering 100% of container and .item-1 height is 120% (it's mean that it height is 20% more than .item-2) and covering 20% of container.
Cause of that .item-1 is before .item-2, .item-1 will be showing on .item-2.
as the Reference explained:
This property is useful when an element is rotated. It lets you choose
if the user should see the back face or not.
When container has rotated, .item-2 will be hidden.

CSS transform: scale makes bottom fixed elements disappear

I'm trying to scale the elements in my body tag so that my website looks the same on differing screen sizes. However, when I apply transform: scale(), the fixed elements associated with bottom disappear. Why is this and how can I fix it?
css
body
{
-moz-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
-webkit-transform: scale(1, 1);
}
#invite
{
position: fixed;
bottom: 20px;
right: 31px;
text-align: center;
cursor: pointer;
}
The invite element disappears when I scale with 1.
It will be more helpful if you could include your code and I think you should use media query if you are trying to make your page responsive.
transform:scale(0.5) will create a new binding box for the position:fixed; element, (when that element is a child of the transformed item)
relevant Stackoverflow question
and further explanations in the chromium bug tracker
Example 'buggy' behaviour:
div {
margin: 20px;
padding: 20px;
}
.body {
background: olive;
min-height:600px
}
.main {
background: pink;
}
.bottom {
background: orange;
position: fixed;
bottom: 0;
}
.body:hover {
transform: scale(1)
}
<div class='body'>
<div class="main">
main content</div>
<div class="bottom"> bottom content </div>;
</div>
As for alternatives: responsive design; the general philosophy is to re-arrange elements into a single vertical stack as the viewport gets smaller.

Why they use backface-visibility:hidden, though a flippable card work fine without it?

In many tutorial, they use backface-visibility:hidden to make a flippable card. But it(card) works fine without backface-visibility:hidden. So why they use it? Any solution.
Css:
.scene {
width: 200px;
height: 260px;
perspective: 600px;
}
.card {
width: 100%;
height: 100%;
position: relative;
transition: transform 1s;
transform-style: preserve-3d;
}
.card:hover{
transform:rotateY(180deg);
}
.card__face {
position: absolute;
height: 100%;
width: 100%;
backface-visibility: ;
/*works fine without backface-visibility:hidden */
}
.card__face--front {
background: red;
}
.card__face--back {
background: blue;
transform: rotateY( 180deg );
}
Link: https://codepen.io/nur49/pen/QWKaQRv
What it does is determine whether the image will show when flipped. A use case would be if you only have content on one side and not the other as in this example. If you don't add the css rule, you will still see it through the other side, but obviously backwards. Typically you do see flipcards with info on both sides, so most cases it might not be entirely necessary. Below is the code example from here.
body {
font-family: sans-serif;
font-size: 0.8rem;
}
div {
position: relative;
height: 60px;
width: 60px;
background-color: red;
transform: rotateY(180deg);
}
#div1 {
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
}
#div2 {
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: visible;
}
<h1>The backface-visibility Property</h1>
<p>This example shows the back face of two div elements.</p>
<p>This div element has "backface-visibility: hidden", and the back face of the div element is invisible:</p>
<div id="div1">DIV 1</div>
<p>This div element has "backface-visibility: visible", and the back face of the div element shows a mirror image of the front face:</p>
<div id="div2">DIV 2</div>
<p><strong>Note:</strong> The backface-visibility property is not supported in Internet Explorer 9 and earlier versions. Safari supports it with a webkit prefix.</p>

How to fix the code for hovering an image, then show a bigger version of that image with the same resolution?

I am currently writing a website and here is the outlook
.
Ideally, I want it to show me the same image, but with bigger size and same resolution. What I did is having 2 identical images, one big one small. Here is my code:
the "heading div" is the banner on top while the "content div" is the image as well as where I would like to have the hover effect. I played around and looked up many different ways to solve this online, but I still cannot figure out how to do so, can someone help me out please?
ADDED:
To be more direct on what I am trying to do, I made this Axure mock up: http://muzuf7.axshare.com . The idea here is having a smaller image on inside the tile and having a mouse-hover function. When hover to the smaller image, the bigger image shows up on top of the smaller image. It will be really clear if you interact with the Axure mock up that I did.
If I am understanding you correctly, you can do something like the following where you can increase the image's size on hover but contain it within a div using overflow: hidden. Obviously you can use transitions and whatnot to make this effect prettier than it is here:
HTML:
<div class="content">
<div id="magic">
<a id="hover"><img src="img.png" alt="Vienna Parliament" /></a>
</div>
</div>
CSS:
.content img {
width: 100%;
height: 100%;
}
#magic {
max-width: 200px;
max-height: 100px;
overflow: hidden;
}
.content img:hover {
width: 110%;
height: 110%;
}
Is that the type of thing you're looking for?
You can make it using Scale on Hover with Transition. Here I make small demo.
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.item {
position: relative;
border: 1px solid #333;
margin: 2%;
overflow: hidden;
width: 540px;
}
.item img {
max-width: 100%;
-moz-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.item:hover img {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
<div class="item">
<img src=http://dummyimage.com/600x400/000/fff.png " width="540 " height="548 ">
<div class="item-overlay top "></div>
</div>
For more details & effects check here