_inner-border.scss.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js">@function inner-border-spread($width) {
  19. $top: top($width);
  20. $right: right($width);
  21. $bottom: bottom($width);
  22. $left: left($width);
  23. @return min(($top + $bottom) / 2, ($left + $right) / 2);
  24. }
  25. @function inner-border-hoff($width, $spread) {
  26. $left: left($width);
  27. $right: right($width);
  28. @if $right &lt;= 0 {
  29. @return $left - $spread;
  30. }
  31. @else {
  32. @return $spread - $right;
  33. }
  34. }
  35. @function inner-border-voff($width, $spread) {
  36. $top: top($width);
  37. $bottom: bottom($width);
  38. @if $bottom &lt;= 0 {
  39. @return $top - $spread;
  40. }
  41. @else {
  42. @return $spread - $bottom;
  43. }
  44. }
  45. @function even($number) {
  46. @return ceil($number / 2) == ($number / 2);
  47. }
  48. @function odd($number) {
  49. @return ceil($number / 2) != ($number / 2);
  50. }
  51. @function inner-border-usesingle-width($width) {
  52. $top: top($width);
  53. $right: right($width);
  54. $bottom: bottom($width);
  55. $left: left($width);
  56. @if $top == 0 {
  57. @if $left + $right == 0 {
  58. @return true;
  59. }
  60. @if $bottom &gt;= $left + $right {
  61. @return true;
  62. }
  63. }
  64. @if $bottom == 0 {
  65. @if $left + $right == 0 {
  66. @return true;
  67. }
  68. @if $top &gt;= $left + $right {
  69. @return true;
  70. }
  71. }
  72. @if $left == 0 {
  73. @if $top + $bottom == 0 {
  74. @return true;
  75. }
  76. @if $right &gt;= $top + $bottom {
  77. @return true;
  78. }
  79. }
  80. @if $right == 0 {
  81. @if $top + $bottom == 0 {
  82. @return true;
  83. }
  84. @if $left &gt;= $top + $bottom {
  85. @return true;
  86. }
  87. }
  88. @if $top + $bottom == $left + $right and even($top) == even($bottom) and even($left) == even($right) {
  89. @return true;
  90. }
  91. @return false;
  92. }
  93. @function inner-border-usesingle-color($color) {
  94. $top: top($color);
  95. $right: right($color);
  96. $bottom: bottom($color);
  97. $left: left($color);
  98. @if $top == $right == $bottom == $left {
  99. @return true;
  100. }
  101. @return false;
  102. }
  103. @function inner-border-usesingle($width, $color) {
  104. @if inner-border-usesingle-color($color) and inner-border-usesingle-width($width) {
  105. @return true;
  106. }
  107. @return false;
  108. }
  109. @mixin inner-border($width: 1px, $color: #fff, $blur: 0px) {
  110. @if inner-border-usesingle($width, $color) {
  111. $spread: inner-border-spread($width);
  112. $hoff: inner-border-hoff($width, $spread);
  113. $voff: inner-border-voff($width, $spread);
  114. @include single-box-shadow($color-top, $hoff, $voff, $blur, $spread, true);
  115. }
  116. @else {
  117. $width-top: top($width);
  118. $width-right: right($width);
  119. $width-bottom: bottom($width);
  120. $width-left: left($width);
  121. $color-top: top($color);
  122. $color-right: right($color);
  123. $color-bottom: bottom($color);
  124. $color-left: left($color);
  125. $shadow-top: false;
  126. $shadow-right: false;
  127. $shadow-bottom: false;
  128. $shadow-left: false;
  129. @if $width-top &gt; 0 {
  130. $shadow-top: $color-top 0 $width-top $blur 0 inset;
  131. }
  132. @if $width-right &gt; 0 {
  133. $shadow-right: $color-right (-1 * $width-right) 0 $blur 0 inset;
  134. }
  135. @if $width-bottom &gt; 0 {
  136. $shadow-bottom: $color-bottom 0 (-1 * $width-bottom) $blur 0 inset;
  137. }
  138. @if $width-left &gt; 0 {
  139. $shadow-left: $color-left $width-left 0 $blur 0 inset;
  140. }
  141. @include box-shadow($shadow-top, $shadow-bottom, $shadow-right, $shadow-left);
  142. }
  143. }</pre>
  144. </body>
  145. </html>