Skip to content

Instantly share code, notes, and snippets.

@jmporchet
Last active January 22, 2021 21:55
Show Gist options
  • Save jmporchet/df48cb34477fc788b670f87f829aa6d5 to your computer and use it in GitHub Desktop.
Save jmporchet/df48cb34477fc788b670f87f829aa6d5 to your computer and use it in GitHub Desktop.
How to hide HTML elements if there's not enough space to display them integrally
<html>
<body>
<style type="text/css">
.container {
width: 300px;
height: 200px;
display: flex;
/* put the undesirable elements on a second column */
flex-flow: column wrap;
/* hide that second column */
overflow: hidden;
}
.box {
width: 300px;
height: 75px;
}
.box:nth-child(1) {
background: red;
}
.box:nth-child(2) {
background: green;
}
.box:nth-child(3) {
background: blue;
}
</style>
<div class='container'>
<div class="box">shown</div>
<div class="box">shown</div>
<div class="box">hidden</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment