Last active
May 19, 2021 03:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, works perfect.