Skip to content

Instantly share code, notes, and snippets.

@chatoo2412
Last active July 23, 2017 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chatoo2412/e89cdb167dc5560b30b02c02d4b4b28e to your computer and use it in GitHub Desktop.
Save chatoo2412/e89cdb167dc5560b30b02c02d4b4b28e to your computer and use it in GitHub Desktop.
Useful flexbox helpers
// Polyfill IE10 http://stackoverflow.com/a/22021384/2480917
@mixin flex($display: flex) {
display: $display;
> *,
&::before,
&::after {
display: block;
}
}
@mixin flex-layout($fluid-selector, $top-selector) {
@include flex;
justify-content: space-between;
align-items: center;
> * {
flex-shrink: 0;
}
> #{$fluid-selector} {
flex-shrink: 1;
flex-grow: 1;
min-width: 0;
}
@if ($top-selector) {
> #{$top-selector} {
align-self: flex-start;
}
}
}
[my-flex] {
@include flex-layout('[my-flex-item-fluid]', '[my-flex-item-top]');
}
<div id="container" my-flex>
<div class="child" my-flex-item-top>
<img src="http://lorempixel.com/80/80/" width="80" height="80">
</div>
<div class="child" my-flex-item-fluid>
<p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="child">
<input type="button">button</input>
</div>
</div>
@include 'utils';
* {
box-sizing: border-box;
}
#container {
width: 640px;
border: 2px dashed black;
}
.child {
border: 2px dashed red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment