Skip to content

Instantly share code, notes, and snippets.

@temsool
Forked from mucsher/margin-padding.less
Last active November 21, 2015 09:09
Show Gist options
  • Save temsool/38610a164d7a0e601a54 to your computer and use it in GitHub Desktop.
Save temsool/38610a164d7a0e601a54 to your computer and use it in GitHub Desktop.
Function Less: Margin and Padding Utilities Class
// Define Style Margin - Padding
.marginAndPadding(@iterations)
{
.p0 {padding: 0px;}
.pT0{padding-top: 0px;}
.pR0{padding-right: 0px;}
.pB0{padding-bottom: 0px;}
.pL0{padding-left: 0px;}
.m0 {margin: 0px;}
.mT0{margin-top: 0px;}
.mR0{margin-right: 0px;}
.mB0{margin-bottom: 0px;}
.mL0{margin-left: 0px;}
.p0-ipt {padding: 0px!important;}
.pT0-ipt{padding-top: 0px!important;}
.pR0-ipt{padding-right: 0px!important;}
.pB0-ipt{padding-bottom: 0px!important;}
.pL0-ipt{padding-left: 0px!important;}
.m0-ipt {margin: 0px!important;}
.mT0-ipt{margin-top: 0px!important;}
.mR0-ipt{margin-right: 0px!important;}
.mB0-ipt{margin-bottom: 0px!important;}
.mL0-ipt{margin-left: 0px!important;}
// LOOP
.style_margin_padding (@index) when (@index > 0) {
// Padding
.p@{index} {padding: ~"@{index}px";}
.pT@{index} {padding-top: ~"@{index}px";}
.pR@{index} {padding-right: ~"@{index}px";}
.pB@{index} {padding-bottom: ~"@{index}px";}
.pL@{index} {padding-left: ~"@{index}px";}
// Padding Important
.p@{index}-ipt {padding: ~"@{index}px!important";}
.pT@{index}-ipt {padding-top: ~"@{index}px!important";}
.pR@{index}-ipt {padding-right: ~"@{index}px!important";}
.pB@{index}-ipt {padding-bottom: ~"@{index}px!important";}
.pL@{index}-ipt {padding-left: ~"@{index}px!important";}
// Padding Horizatial
.p-@{index}-h {padding: 0 ~"@{index}px";}
.p-@{index}-h-ipt {padding: 0 ~"@{index}px!important";}
// Padding Vertical
.p-@{index}-v {padding: ~"@{index}px" 0;}
.p-@{index}-v-ipt {padding: ~"@{index}px" 0!important;}
//-----------------------------------------------------------------
// Margin
.m@{index} {margin: ~"@{index}px";}
.mT@{index} {margin-top: ~"@{index}px";}
.mR@{index} {margin-right: ~"@{index}px";}
.mB@{index} {margin-bottom: ~"@{index}px";}
.mL@{index} {margin-left: ~"@{index}px";}
// Margin Important
.m@{index}-ipt {margin: ~"@{index}px!important";}
.mT@{index}-ipt {margin-top: ~"@{index}px!important";}
.mR@{index}-ipt {margin-right: ~"@{index}px!important";}
.mB@{index}-ipt {margin-bottom: ~"@{index}px!important";}
.mL@{index}-ipt {margin-left: ~"@{index}px!important";}
// margin Horizatial
.m-@{index}-h {margin: 0 ~"@{index}px";}
.m-@{index}-h-ipt {margin: 0 ~"@{index}px!important";}
// margin Vertical
.m-@{index}-v {margin: ~"@{index}px" 0;}
.m-@{index}-v-ipt {margin: ~"@{index}px" 0!important;}
// next iteration
.style_margin_padding(@index - 5);
}
// end the loop when index is 0
/* .style_margin_padding (0) {}*/
// "call" the loopingClass the first time with highest value
.style_margin_padding (@iterations);
}
.marginAndPadding(50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment