Skip to content

Instantly share code, notes, and snippets.

@pbakaus
Created July 27, 2016 23:11
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 pbakaus/af4effedc249f280614490c563beaef9 to your computer and use it in GitHub Desktop.
Save pbakaus/af4effedc249f280614490c563beaef9 to your computer and use it in GitHub Desktop.
Flexbox freebie: Auto-growing list (for AMP Roadmap)
.steps {
...
/* enable flex, wrap all items.
* - align-items' and align-content's default are set to 'stretch',
* so li's automatically evenly distributed and stretched
*/
display: flex;
flex-wrap: wrap;
....
/* alternative to built-in list style that we can style */
list-style-type: none;
counter-reset: steps;
}
/* the steps (li) */
.steps > li {
...
/* gives items an explicit width, so we do things like
* like ellipsis in overflowing text..
*/
flex: 1 1 100%;
...
border-left: 3px solid;
counter-increment: steps;
}
/* the smallish description label next to the bubble */
.steps > li::before {
/* show number + description from attribute in heading */
content: "Step " counter(steps) ": " attr(data-description);
...
}
/* the bubble with the number in it */
.steps > li::after {
...
/* show the number from the counter in the pseudo element */
content: counter(steps);
}
<ol class="steps">
<li data-description="Step 1 description">
<ul>
<li>Substep 1</li>
<li>Substep 2</li>
<li>Substep 3</li>
</ul>
</li>
<li data-description="Step 2 description">
<ul>
<li>Substep 1</li>
<li>Substep 2</li>
</ul>
</li>
</ol>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment