|
| 1 | +--- |
| 2 | +title: Spacing |
| 3 | +description: This SCSS snippet dynamically generates utility classes for managing spacing in a consistent and efficient manner. The classes are built using a loop, ensuring scalability and flexibility. use .mt-* for margin-top, and .pb-* for padding bottom |
| 4 | +author: dinesh-here |
| 5 | +tags: clearfix,utility,css, spacing |
| 6 | +--- |
| 7 | + |
| 8 | +```scss |
| 9 | +$step: 5; |
| 10 | +$start_limit: 0; |
| 11 | +$end_limit: 50; |
| 12 | + |
| 13 | + @while $start_limit <= $end_limit { |
| 14 | + .mt-#{$start_limit} { |
| 15 | + margin-top: $start_limit + px; |
| 16 | + } |
| 17 | + .mb-#{$start_limit} { |
| 18 | + margin-bottom: $start_limit + px; |
| 19 | + } |
| 20 | + |
| 21 | + .ml-#{$start_limit} { |
| 22 | + margin-left: $start_limit + px; |
| 23 | + } |
| 24 | + |
| 25 | + .mr-#{$start_limit} { |
| 26 | + margin-right: $start_limit + px; |
| 27 | + } |
| 28 | + |
| 29 | + .pt-#{$start_limit} { |
| 30 | + padding-top: $start_limit + px; |
| 31 | + } |
| 32 | + .pb-#{$start_limit} { |
| 33 | + padding-bottom: $start_limit + px; |
| 34 | + } |
| 35 | + |
| 36 | + .pl-#{$start_limit} { |
| 37 | + padding-left: $start_limit + px; |
| 38 | + } |
| 39 | + |
| 40 | + .pr-#{$start_limit} { |
| 41 | + padding-right: $start_limit + px; |
| 42 | + } |
| 43 | + .mx-#{$start_limit} { |
| 44 | + margin-left: $start_limit + px; |
| 45 | + margin-right: $start_limit + px; |
| 46 | + } |
| 47 | + |
| 48 | + .px-#{$start_limit} { |
| 49 | + padding-left: $start_limit + px; |
| 50 | + padding-right: $start_limit + px; |
| 51 | + } |
| 52 | + |
| 53 | + .my-#{$start_limit} { |
| 54 | + margin-top: $start_limit + px; |
| 55 | + margin-bottom: $start_limit + px; |
| 56 | + } |
| 57 | + |
| 58 | + .py-#{$start_limit} { |
| 59 | + padding-top: $start_limit + px; |
| 60 | + padding-bottom: $start_limit + px; |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + $start_limit: $start_limit + $step; |
| 65 | +} |
| 66 | + |
| 67 | +``` |
0 commit comments