I made a sidebar that collapses/opens with animation. The site can either be RTL or LTR.
.sidebar {
max-width: 380px;
width: 85%;
height: 100%;
position: fixed;
z-index: 100;
top: 0;
inset-inline-start: 0;
padding: 10px 20px;
transform: translateX(100%);
transition: transform 0.3s ease;
}
For the RTL website, I can use:
transform: translateX(100%);
and it will hide it, but on LTR, it will move it to the right side from the left.
I used inset-inline-start instead of right/left.
How can I then use translateX to hide the sidebar regardless of the dir attribute, so that on RTL it will hide it to the right side, and on LTR to the left.
I could use some manual setting like so:
:root {
--sidebar-translate: -100%; /* move left off-screen */
}
/* RTL override */
:dir(rtl) {
--sidebar-translate: 100%; /* move right off-screen */
}
and then:
transform: translateX(var(--sidebar-translate));
But maybe there's a better/cleaner way?