Skip to content

Instantly share code, notes, and snippets.

@hugohabel
Last active July 30, 2021 00:42
Show Gist options
  • Save hugohabel/794c4027f0cd76b07a95accf6da58a75 to your computer and use it in GitHub Desktop.
Save hugohabel/794c4027f0cd76b07a95accf6da58a75 to your computer and use it in GitHub Desktop.
Basics of Flexbox
<!DOCTYPE html>
<html>
<head>
<style>
/* Additional Styles */
* {
box-sizing: border-box;
}
.icon {
border-radius: 8px;
padding: 16px 24px;
cursor: pointer;
}
.icon:hover {
}
.icon > h2 {
font-size: 16px;
margin: 8px 0;
color: #FCFCFC;
}
.bg-1 {
background: #86DBC9;
}
.bg-2 {
background: #4B4E6B;
}
.bg-3 {
background: #F3AC4A;
}
.icon-logo {
width: 32px;
}
.attribution {
margin-top: 16px;
text-align: center;
}
/* End Additional Styles */
/* Flexbox Styles - Demo */
.container {
display: flex;
justify-content: space-around;
/* flex-direction: column; */
/* height: 50vh; */
}
.box {
align-items: center;
display: flex;
flex-direction: column;
flex-basis: 96px;
}
.box-1 {
order: 3;
}
.box-2 {
order: 2;
}
.box-3 {
order: 1;
}
/* End Flexbox Styles - Demo */
</style>
</head>
<body>
<!-- Main Container -->
<div class="container">
<!-- Box 1 -->
<div class="box box-1 icon bg-1">
<img src="static/cargo-ship.png" class="icon-logo"/>
<h2>Cargo</h2>
</div>
<!-- End Box 1 -->
<!-- Box 2 -->
<div class="box box-2 icon bg-2">
<img src="static/compass.png" class="icon-logo"/>
<h2>Compass</h2>
</div>
<!-- End Box 2 -->
<!-- Box 3 -->
<div class="box box-3 icon bg-3">
<img src="static/hook.png" class="icon-logo"/>
<h2>Hook</h2>
</div>
<!-- End Box 3 -->
</div>
<!-- End Main Container -->
<!-- Attribution -->
<div class="attribution">
Icons made by <a href="https://www.freepik.com" title="Freepik">Freepik</a>
from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>
</div>
<!-- End Attribution -->
</body>
</html>
@hugohabel
Copy link
Author

Sample output of this gist

flexbox-1

flexbox-2

Flexbox tips & tricks:

  • align-* properties work on the cross axis, while the justify-* properties work on the main axis.

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