Fly-out menus are an efficient way to handle navigation when space is tight, but they carry a familiar drawback: what they reveal, they also cover. The approach below keeps a hidden menu's compactness while leaving the current page content visible and intact. A hidden checkbox drives the toggle, and CSS transitions do the reveal so that the page appears to swing open on its left edge.
Preparing the markup
The menu has two states, open and closed. Those states rely on the Checkbox Hack. A checkbox is checked or unchecked, which is exactly the state toggled by the input's :checked selector, so we hide the actual checkbox with CSS and place it beneath the menu icon; the user interacts with the icon, not the checkbox. Checking it opens the menu, unchecking it closes the menu. A JavaScript class toggle is an equally valid alternative if that better fits the project.
The checkbox must precede the page content in source order, because the selector that opens the menu uses a sibling relationship. Grid or Flexbox layouts can compensate if that order creates layout concerns, since both are source-order independent.
Here is the base structure:
<input type="checkbox">
<div id="menu">
<!--menu options-->
</div>
<div id="page">
<!--main content-->
</div>
The checkbox is hidden with the appearance property so that the browser's default square never shows. Then a pseudo-element is added to serve as the menu icon, and the demo uses a full size background image for the #page content.
/* Hide checkbox and reset styles */
input[type="checkbox"] {
appearance: initial; /* removes the square box */
border: 0; margin: 0; outline: none; /* removes default margin, border and outline */
width: 30px; height: 30px; /* sets the menu icon dimensions */
z-index: 1; /* makes sure it stacks on top */
}
/* Menu icon */
input::after {
content: "\2255";
display: block;
font: 25pt/30px "georgia";
text-indent: 10px;
width: 100%; height: 100%;
}
/* Page content container */
#page {
background: url("earbuds.jpg") #ebebeb center/cover;
width: 100%; height: 100%;
}
The rotate and scale transition
Clicking the menu control does two things. First, the icon changes into an ×, so it reads as a way to close the menu. That means targeting the checkbox's ::after pseudo-element when the input is in a :checked state:
input:checked::after {
content: "\00d7"; /* changes to × mark */
color: #ebebeb;
}
Second, the main content transforms. It moves to the right, rotates, scales down, and its left corners become angular, so that it looks pushed back like a door swung open, with the menu now visible underneath it.
input:checked ~ #page {
clip-path: polygon(0 8%, 100% 0, 100% 100%, 0 92%);
transform: translateX(40%) rotateY(10deg) scale(0.8);
transform-origin: right center;
transition: all .3s linear;
}
That corner change comes from clip-path. Because it is transitioned, #page needs an initial clip-path value to transition from, and a transition declaration of its own; that declaration means the menu closes as smoothly as it opens.
#page {
background: url("earbuds.jpeg") #ebebeb center/cover;
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
transition: all .3s linear;
width: 100%; height: 100%;
}
Unchecking the box, which happens when the × mark is clicked, reverses the transform automatically and the content returns to the front and centre.
An optional click-away enhancement
One extra step improves the experience: closing the menu when the user clicks or taps the #page element. That means the × mark doesn't have to be found or pressed. This is a progressive enhancement written in JavaScript, so it does not stop the menu from working if scripting is unavailable.
document.querySelector("#page").addEventListener('click', (e, checkbox = document.querySelector('input')) => {
if (checkbox.checked) { checkbox.checked = false; e.stopPropagation(); }
});
The snippet attaches a click event handler to #page. If the checkbox is in its :checked state, it unchecks the box, which closes the menu.
The demo targets a vertical, portrait layout but also works at wider landscape screen sizes, depending on the content involved.



