Skip to content

Instantly share code, notes, and snippets.

@dwayne
Last active May 19, 2021 03:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwayne/6829795 to your computer and use it in GitHub Desktop.
Save dwayne/6829795 to your computer and use it in GitHub Desktop.
How to make a horizontal list span the width of its container element
// Thanks to CSS Tricks for the inspiration: http://css-tricks.com/equidistant-objects-with-css/
@mixin horizontal-list-span-width {
margin: 0;
padding: 0;
list-style-type: none;
text-align: justify;
&:after {
content: '';
width: 100%;
display: inline-block;
}
& > li {
display: inline-block;
}
}
// Usage
//
// 1. Assume the following markup:
//
// <div class="parent">
// <ul class="items">
// <li>Item 1</li>
// <li>Item 2</li>
// <li>Item 3</li>
// </ul>
// </div>
//
// 2. We want the items to span the width of the parent. Equally spaced of course.
.items {
@include horizontal-list-span-width;
}
// One issue I have with this solution is that it creates some space beneath ul.items that I cannot seem to remove.
@alexandru-burca
Copy link

Thank you, works perfect.

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