Skip to content

Instantly share code, notes, and snippets.

@kilmc
Last active April 9, 2018 16:49
Show Gist options
  • Select an option

  • Save kilmc/7871228 to your computer and use it in GitHub Desktop.

Select an option

Save kilmc/7871228 to your computer and use it in GitHub Desktop.
Border Sandwich Mixin

Border Sandwich Mixin

A simple mixin to create top and bottom borders on elements

Default Usage

You can define the sandwich with a regular border definition

@include border-sandwich(1px solid black)

Which give the following result
----------------------------
First Item
----------------------------
Second Item
----------------------------
Third Item
----------------------------

Just Filling Usage

To make this border sandwich just have filling, simply add a true argument to the end of your @include

@include border-sandwich(1px solid black, true)

First Item
----------------------------
Second Item
----------------------------
Third Item

Thanks

Thanks to @paulzoom for his help on this, especially with getting it IE9+ compatiable

@mixin border-sandwich($border, $just-filling: false) {
@if ($just-filling) {
&:not(:first-of-type) {
border-top: $border;
}
} @else {
border-bottom: $border;
&:first-of-type {
border-top: $border;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment