Here is a code showing my issue
.container {
width: 200px;
height: 200px;
overflow: auto;
}
.child {
width: 400px;
height: 400px;
/* When scaling down, no more X scrolling because size is 200px, but still Y scrolling :( */
transform: scale(0.5);
/* Both axis working the same (no more scrolling) when absolutely positioned */
/* position: absolute; */
}
/* Irrelevant styling */
.container {
border: 2px solid palevioletred;
position: relative;
}
.child {
background-color: pink;
transform-origin: top left;
}
<div class="container">
<div class="child">
Child
</div>
</div>
Try to scroll down or right within the box.
- There is a container with a fixed size, containing a child also with a fixed size.
- There is overflow scrolling.
Then I scale down the child with a transformation, halving its size.
- The X scroll disappears because child's width is 200px (more specifically, container's scrollWidth property has shrinked accordingly)
- The Y scroll is still there and the container's scrollHeight property is still the same.
I can somewhat understand the behavior of each axis, but not why they're acting differently.
Ideally I'd like the Y axis to act like the X axis.
If I set position:absolute on the child, then the Y axis acts as the X axis (Both scrolls disappears).
.container {
width: 200px;
height: 200px;
overflow: auto;
}
.child {
width: 400px;
height: 400px;
position:absolute;
transform: scale(0.5);
}
/* Irrelevant styling */
.container {
border: 2px solid palevioletred;
position: relative;
}
.child {
background-color: pink;
transform-origin: top left;
}
<div class="container">
<div class="child">
Child
</div>
</div>
Try to scroll down or right within the box.
Same thing when I set display:inline-block. Both axis behave the sames (Both scrolls aren't affected by scale)
.container {
width: 200px;
height: 200px;
overflow: auto;
}
.child {
width: 400px;
height: 400px;
display:inline-block;
transform: scale(0.5);
}
/* Irrelevant styling */
.container {
border: 2px solid palevioletred;
position: relative;
}
.child {
background-color: pink;
transform-origin: top left;
}
<div class="container">
<div class="child">
Child
</div>
</div>
Try to scroll down or right within the box.
Why in the initial case, we have a different behavior? And why in some cases, the scale change the scroll (when we used position:absolute) and in other cases it doesn't (when we used display:inline-block).
As a side note, transform is a visual effect that doesn't affect the layout so logically the scroll shouldn't change in all the cases.