Skip to content

Instantly share code, notes, and snippets.

@jpnelson
Last active June 14, 2022 16:51
Show Gist options
  • Save jpnelson/52d6f38820c6d028bdf8 to your computer and use it in GitHub Desktop.
Save jpnelson/52d6f38820c6d028bdf8 to your computer and use it in GitHub Desktop.
Responsive, resizable panel layout with flexbox
.container {
height: 500px;
border: 2px solid grey;
position:relative;
}
.split {
display: flex;
height: 100%;
border: 1px solid black;
}
.split > :nth-child(1) {
overflow: scroll;
}
.split > :nth-child(2) {
flex-grow: 1;
}
/* Vertical */
.split.vertical {
flex-direction: column;
}
.split.vertical > :nth-child(1) {
resize: vertical;
}
/* Horizontal */
.split.horizontal {
flex-direction: row;
}
.split.horizontal > :nth-child(1) {
resize: horizontal;
}
.split div {
padding: 5px;
border: 1px dashed black;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Split panels</title>
</head>
<body>
<div class="container">
<div class="split horizontal">
<div class="split vertical">
<div>
A
</div>
<div>
B
</div>
</div>
<div>
C
</div>
</div>
</div>
</body>
</html>
@sbruchmann
Copy link

Thank you very much, this will come in handy!

Just a minor nit: I had to add

* {
  box-sizing: border-box;
}

for obvious reasons.

@johnrnelson
Copy link

Simple and elegant. I love it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment