forked from NigelOToole/angled-edges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_angled-edges.scss
95 lines (75 loc) · 2.44 KB
/
_angled-edges.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// $angle: The angle in degrees: 1 - 45
// $angle-position-y: The Y position of the angle: top | bottom | both
// $angle-position-x: The X position of the angle: left | right
// $angle-position-bottom-x: The X position of the bottom angle if using 'both' for $angle-position-y: left | right
// $color: Color of angled edge: Hex color
@mixin angled-edge($angle, $angle-position-y, $angle-position-x, $color: #ffffff, $angle-position-bottom-x: '') {
position: relative;
overflow: hidden;
// Converts degrees to VW, 100vw = 45deg using this technique
@if $angle < 46 {
$angle: convertDegToVW($angle);
}
@if $angle > 45 {
$angle: 0;
@error 'Invalid angle, it must be between 1-45';
}
@if $angle-position-bottom-x == '' {
$angle-position-bottom-x: $angle-position-x;
}
$border-width-top: '';
$border-width-bottom: '';
$border-color-top: '';
$border-color-bottom: '';
@if $angle-position-y == 'top' or $angle-position-y == 'both' {
@if $angle-position-x == 'left' {
$border-width-top: #{$angle + 1}vw 100vw 0 0;
}
@if $angle-position-x == 'right' {
$border-width-top: #{$angle + 1}vw 0 0 100vw;
}
$border-color-top: $color transparent transparent transparent;
}
@if $angle-position-y == 'bottom' or $angle-position-y == 'both' {
@if $angle-position-y == 'both' and $angle-position-x != $angle-position-bottom-x {
$angle-position-x: $angle-position-bottom-x;
}
@if $angle-position-x == 'left' {
$border-width-bottom: 0 100vw #{$angle + 1}vw 0;
}
@if $angle-position-x == 'right' {
$border-width-bottom: 0 0 #{$angle + 1}vw 100vw;
}
$border-color-bottom: transparent transparent $color transparent;
}
@if $angle-position-y == 'top' or $angle-position-y == 'both' {
&::before {
content: "";
position: absolute;
left: 0;
z-index: 10;
display: block;
border-style: solid;
top: 0;
border-width: $border-width-top;
border-color: $border-color-top;
}
}
@if $angle-position-y == 'bottom' or $angle-position-y == 'both' {
&::after {
content: "";
position: absolute;
left: 0;
z-index: 10;
display: block;
border-style: solid;
bottom: 0;
border-width: $border-width-bottom;
border-color: $border-color-bottom;
}
}
}
// Converts degrees to VW, 100vw = 45deg using this technique
@function convertDegToVW($angle){
@return $angle*2.22;
}