-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwriteup.htm
612 lines (606 loc) · 23.3 KB
/
writeup.htm
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
<!DOCTYPE html>
<html>
<head>
<title>Arrows</title>
<link rel="stylesheet" type="text/css" href="content/style.css">
<!--[if gte IE 9]>
<style
type="text/css">
.gradient {
filter: none;
}
</style>
<![endif]-->
</head>
<body>
<div class="container">
<h1>3 Styles of CSS Arrows</h1>
<em>By James Gould, 2/21/2015</em>
<p>
With CSS, you can create a wide array of easily modifiable shapes,
to great effect. In this article, I explain and document three manners
and discuss what can be done with each kind.
</p>
<h3>CSS Triangles</h3>
<p>
First, we have CSS triangles made from borders. These are created using the
border CSS attribute. When CSS renders a border, it generally creates
four trapezoids on the sides of the object, as you can see below.
When the smallest side of the "trapezoid" reaches 0 width,
it becomes a triangle. You may also note that any two of the sides
of the final example form a right triangle as well.
</p>
<h5><div>'s with borders:</h5>
<div class="example">
<div class="border regular"></div>
<div class="border mid"></div>
<div class="border larger"></div>
<div class="border largest"></div>
<div class="border triangles"></div>
<div class="clear"></div>
</div>
<p>
Then, if we remove three sides of the triangle by making them transparent,
and removing the side we don't want, we get a triangle. By changing the
width of the border, we can then make a triangle with any dimensions.
You can use
<a target="_blank" href="http://apps.eky.hk/css-triangle-generator/">
this CSS triangle generator to play around with CSS triangles.
</a>
</p>
<div class="example">
<div class="triangle"></div>
<div class="triangle tall"></div>
<div class="triangle long"></div>
<div class="triangle fat"></div>
<div class="clear"></div>
</div>
<p>
We can then add triangular mask, made with the same technique,
over the triangle to make it an arrow. I use the before and after
pseudo-elements as masks, and I recommend you do the same, as it keeps
your HTML clean of unnecessary clutter. The masks are displayed in
red below, and then in the background color, white, in the second example.
There is unfortunately no effective way to use masks like this on images
and gradients, as you cannot make them transparent.
</p>
<div class="example">
<div class="arrow showAfter"></div>
<div class="arrow tall showAfter"></div>
<div class="arrow long showAfter"></div>
<div class="arrow fat showAfter"></div>
<div class="clear"></div>
<div class="arrow"></div>
<div class="arrow tall"></div>
<div class="arrow long"></div>
<div class="arrow fat"></div>
<div class="clear"></div>
</div>
<h3>Triangle Examples (click to view HTML, CSS and masks)</h3>
<div data-id="#c-te1" class="cnt">
<div class="triangle"></div>
</div>
<div data-id="#c-te2" class="cnt">
<div class="arrow"></div>
</div>
<div data-id="#c-te3" class="cnt">
<div class="arrow tall"></div>
</div>
<div data-id="#c-te4" class="cnt">
<div class="arrow long"></div>
</div>
<div data-id="#c-te5" class="cnt">
<div class="arrow fat"></div>
</div>
<div data-id="#c-te6" class="cnt">
<div class="arrow skinny"></div>
</div>
<div class="clear"></div>
<code id="c-te1">
<div class="triangle"></div><br>
<style><br>
.triangle{<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #222;<br>
}<br>
</style>
</code>
<code id="c-te2">
<div class="arrow"></div><br>
<style><br>
.arrow{<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #222;<br>
}<br>
.arrow:after{<br>
content:'';<br>
position:absolute;<br>
transform:translate(-65px, -30px);<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #fff;<br>
}<br>
</style>
</code>
<code id="c-te3">
<div class="arrow tall"></div><br>
<style><br>
.arrow{<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #222;<br>
}<br>
.arrow:after{<br>
content:'';<br>
position:absolute;<br>
transform:translate(-65px, -30px);<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #fff;<br>
}<br>
.arrow.tall{<br>
border-width: 30px 0 30px 30px;<br>
}<br>
.arrow.tall:after{<br>
transform:translate(-40px, -30px);<br>
border-width: 30px 0 30px 30px;<br>
}<br>
</style>
</code>
<code id="c-te4">
<div class="arrow long"></div><br>
<style><br>
.arrow{<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #222;<br>
}<br>
.arrow:after{<br>
content:'';<br>
position:absolute;<br>
transform:translate(-65px, -30px);<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #fff;<br>
}<br>
.arrow.long{<br>
border-width: 20px 0 20px 60px;<br>
}<br>
.arrow.long:after{<br>
transform:translate(-80px, -20px);<br>
border-width: 20px 0 20px 60px;<br>
}<br>
</style>
</code>
<code id="c-te5">
<div class="arrow fat"></div><br>
<style><br>
.arrow{<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #222;<br>
}<br>
.arrow:after{<br>
content:'';<br>
position:absolute;<br>
transform:translate(-65px, -30px);<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #fff;<br>
}<br>
.arrow.fat:after{<br>
transform:translate(-75px, -30px);<br>
}<br>
</style>
</code>
<code id="c-te6">
<div class="arrow skinny"></div><br>
<style><br>
.arrow{<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #222;<br>
}<br>
.arrow:after{<br>
content:'';<br>
position:absolute;<br>
transform:translate(-65px, -30px);<br>
width: 0;<br>
height: 0;<br>
border-style: solid;<br>
border-width: 30px 0 30px 50px;<br>
border-color: transparent transparent transparent #fff;<br>
}<br>
.arrow.skinny:after{<br>
transform:translate(-55px, -30px);<br>
}<br>
</style>
</code>
<h3>Creating CSS Arrows Using Two Border-sides</h3>
<p>
We can also make arrows using two sides of a CSS border on a transparent
square div. These are less flexible, as they are always 90 degrees due to the
box model. However, they can be used on top of images and gradients
without the mask showing up, unlike the previous example. I use
<span class="code">transition:rotate(45deg);</span>
to rotate the following examples to point to the right.
</p>
<div class="example">
<div class="border-arrow fat exampleElem"></div>
<div class="clear"></div>
</div>
<p>
We can then the border-radius attribute to curve the outside corners
of the border, which is another benefit of this style of arrow.
</p>
<div class="example">
<div class="border-arrow curvy exampleElem"></div>
<div class="clear"></div>
</div>
<p>
The top and bottom curves are kind of funky looking in my opinion,
and you can't curve their interiors, and the interior of the point
isn't curved to match the outside. We can fix all of this with a
rectangular CSS masks to flatten the top and bottom points and add an interior
border using the same technique we used to make this triangle like we did
in the previous section with triangles. Again, this will make this triangle
not work on gradient and image backgrounds, as the masks will show up.
</p>
<div class="example">
<div class="border-arrow curvy curvy-inside flat-back exampleElem showMasks"></div>
<div class="border-arrow curvy curvy-inside flat-back exampleElem"></div>
<div class="clear"></div>
</div>
<h3>Border Examples (click to view HTML, CSS and masks)</h3>
<div data-id="#c-boe1" class="cnt">
<div>
<div class="border-arrow"></div>
</div>
</div>
<div data-id="#c-boe2" class="cnt">
<div>
<div class="border-arrow fat"></div>
</div>
</div>
<div data-id="#c-boe3" class="cnt">
<div>
<div class="border-arrow curvy"></div>
</div>
</div>
<div data-id="#c-boe4" class="cnt">
<div>
<div class="border-arrow curvy curvy-inside"></div>
</div>
</div>
<div data-id="#c-boe5" class="cnt">
<div>
<div class="border-arrow curvy curvy-inside flat-back"></div>
</div>
</div>
<div class="clear"></div>
<code id="c-boe1">
<div class="border-arrow"></div><br>
<style><br>
.border-arrow{<br>
width:40px;<br>
height:40px;<br>
border:5px solid #222;<br>
border-width:5px 5px 0 0;<br>
transform:translateX(-14px) rotate(45deg);<br>
}<br>
</style>
</code>
<code id="c-boe2">
<div class="border-arrow fat"></div><br>
<style><br>
.border-arrow{<br>
width:40px;<br>
height:40px;<br>
border:5px solid #222;<br>
border-width:5px 5px 0 0;<br>
transform:translateX(-14px) rotate(45deg);<br>
}<br>
.border-arrow.fat{<br>
border-width:9px 9px 0 0;<br>
}<br>
</style>
</code>
<code id="c-boe3">
<div class="border-arrow curvy"></div><br>
<style><br>
.border-arrow{<br>
width:40px;<br>
height:40px;<br>
border:5px solid #222;<br>
border-width:5px 5px 0 0;<br>
transform:translateX(-14px) rotate(45deg);<br>
}<br>
.border-arrow.curvy{<br>
border-width:9px 9px 0 0;<br>
border-radius:7px;<br>
}<br>
</style>
</code>
<code id="c-boe4">
<div class="border-arrow curvy curvy-inside"></div><br>
<style><br>
.border-arrow{<br>
width:40px;<br>
height:40px;<br>
border:5px solid #222;<br>
border-width:5px 5px 0 0;<br>
transform:translateX(-14px) rotate(45deg);<br>
}<br>
.border-arrow.curvy{<br>
border-width:9px 9px 0 0;<br>
border-radius:7px;<br>
}<br>
.border-arrow.curvy-inside{<br>
border-width:11px 11px 0 0;<br>
}<br>
.border-arrow.curvy-inside:before{<br>
content:'';<br>
display:block;<br>
position:absolute;<br>
width:40px;<br>
height:40px;<br>
border:5px solid #fff;<br>
border-width:5px 5px 0 0;<br>
transform:translate(-2px, -3px);<br>
border-radius:4px;<br>
}<br>
</style>
</code>
<code id="c-boe5">
<div class="border-arrow curvy curvy-inside flat-back"></div><br>
<style><br>
.border-arrow{<br>
width:40px;<br>
height:40px;<br>
border:5px solid #222;<br>
border-width:5px 5px 0 0;<br>
transform:translateX(-14px) rotate(45deg);<br>
}<br>
.border-arrow.curvy{<br>
border-width:9px 9px 0 0;<br>
border-radius:7px;<br>
}<br>
.border-arrow.curvy-inside{<br>
border-width:11px 11px 0 0;<br>
}<br>
.border-arrow.curvy-inside:before{<br>
content:'';<br>
display:block;<br>
position:absolute;<br>
width:40px;<br>
height:40px;<br>
border:5px solid #fff;<br>
border-width:5px 5px 0 0;<br>
transform:translate(-2px, -3px);<br>
border-radius:4px;<br>
}<br>
.border-arrow.flat-back{<br>
transform:translateX(-19px) rotate(45deg);<br>
}<br>
.border-arrow.flat-back:after{<br>
content:'';<br>
display:block;<br>
position:absolute;<br>
width:8px;<br>
height:80px;<br>
background-color:#fff;<br>
transform:translate(20px, -25px) rotate(-45deg);<br>
}<br>
</style>
</code>
<div class="clear"></div>
<h3>Creating CSS Triangles Using Masks</h3>
<p>
Now, I know what you're thinking. "Gradients don't have good browser
support on borders, and the previous methods don't require enough
tweaking to get right!" Well, you can also use a mask over half of a
square div to create a right triangle, which allows you to use gradients on your
triangles. Again, you can use a CSS mask to make them arrows.
</p>
<h3>Box Examples (click to view HTML, CSS and masks)</h3>
<div data-id="#c-bo2e1" class="cnt">
<div>
<div class="box-triangle"></div>
</div>
</div>
<div data-id="#c-bo2e2" class="cnt">
<div>
<div class="box-triangle box-arrow"></div>
</div>
</div>
<div data-id="#c-bo2e3" class="cnt">
<div>
<div class="box-triangle rainbow gradient"></div>
</div>
</div>
<div data-id="#c-bo2e4" class="cnt">
<div>
<div class="box-triangle box-arrow rainbow gradient"></div>
</div>
</div>
<code id="c-bo2e1">
<div class="box-triangle"></div><br>
<style><br>
.box-triangle{<br>
position:relative;<br>
width:50px;<br>
height:50px;<br>
background-color:#222;<br>
transform:translate(-14px, 0) rotate(45deg);<br>
}<br>
.box-triangle:before{<br>
content:'';<br>
position:absolute;<br>
width:35px;<br>
height:70px;<br>
background-color:#fff;<br>
transform:translate(-5px, 3px) rotate(-45deg);<br>
}<br>
</style>
</code>
<code id="c-bo2e2">
<div class="box-triangle box-arrow"></div><br>
<style><br>
.box-triangle{<br>
position:relative;<br>
width:50px;<br>
height:50px;<br>
background-color:#222;<br>
transform:translate(-14px, 0) rotate(45deg);<br>
}<br>
.box-triangle:before{<br>
content:'';<br>
position:absolute;<br>
width:35px;<br>
height:70px;<br>
background-color:#fff;<br>
transform:translate(-5px, 3px) rotate(-45deg);<br>
}<br>
.box-triangle.box-arrow:after{<br>
content:'';<br>
position:absolute;<br>
width:40px;<br>
height:40px;<br>
background-color:#fff;<br>
transform:translate(2px, 8px);<br>
}<br>
</style>
</code>
<code id="c-bo2e3">
<div class="box-triangle rainbow"></div><br>
<style><br>
.box-triangle{<br>
position:relative;<br>
width:50px;<br>
height:50px;<br>
background-color:#222;<br>
transform:translate(-14px, 0) rotate(45deg);<br>
}<br>
.box-triangle:before{<br>
content:'';<br>
position:absolute;<br>
width:35px;<br>
height:70px;<br>
background-color:#fff;<br>
transform:translate(-5px, 3px) rotate(-45deg);<br>
}<br>
.rainbow{<br>
background: #800080; /* Old browsers */<br>
/* for IE9 support details: http://www.colorzilla.com/gradient-editor/ */<br>
background: -moz-linear-gradient(45deg, #800080 52%, #4b0082 56%, #0000ff 62%, #008000 68%, #ffff00 75%, #ffa500 83%, #ff0000 91%, #800080 100%); /* FF3.6+ */<br>
background: -webkit-gradient(linear, left bottom, right top, color-stop(52%,#800080), color-stop(56%,#4b0082), color-stop(62%,#0000ff), color-stop(68%,#008000), color-stop(75%,#ffff00), color-stop(83%,#ffa500), color-stop(91%,#ff0000), color-stop(100%,#800080)); /* Chrome,Safari4+ */<br>
background: -webkit-linear-gradient(45deg, #800080 52%,#4b0082 56%,#0000ff 62%,#008000 68%,#ffff00 75%,#ffa500 83%,#ff0000 91%,#800080 100%); /* Chrome10+,Safari5.1+ */<br>
background: -o-linear-gradient(45deg, #800080 52%,#4b0082 56%,#0000ff 62%,#008000 68%,#ffff00 75%,#ffa500 83%,#ff0000 91%,#800080 100%); /* Opera 11.10+ */<br>
background: -ms-linear-gradient(45deg, #800080 52%,#4b0082 56%,#0000ff 62%,#008000 68%,#ffff00 75%,#ffa500 83%,#ff0000 91%,#800080 100%); /* IE10+ */<br>
background: linear-gradient(45deg, #800080 52%,#4b0082 56%,#0000ff 62%,#008000 68%,#ffff00 75%,#ffa500 83%,#ff0000 91%,#800080 100%); /* W3C */<br>
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#800080', endColorstr='#800080',GradientType=1 ); /* IE6-8 fallback on horizontal gradient */<br>
}<br>
</style>
</code>
<code id="c-bo2e4">
<div class="box-triangle box-arrow rainbow"></div><br>
<style><br>
.box-triangle{<br>
position:relative;<br>
width:50px;<br>
height:50px;<br>
background-color:#222;<br>
transform:translate(-14px, 0) rotate(45deg);<br>
}<br>
.box-triangle:before{<br>
content:'';<br>
position:absolute;<br>
width:35px;<br>
height:70px;<br>
background-color:#fff;<br>
transform:translate(-5px, 3px) rotate(-45deg);<br>
}<br>
.box-triangle.box-arrow:after{<br>
content:'';<br>
position:absolute;<br>
width:40px;<br>
height:40px;<br>
background-color:#fff;<br>
transform:translate(2px, 8px);<br>
}<br>
.rainbow{<br>
background: #800080; /* Old browsers */<br>
/* for IE9 support details: http://www.colorzilla.com/gradient-editor/ */<br>
background: -moz-linear-gradient(45deg, #800080 52%, #4b0082 56%, #0000ff 62%, #008000 68%, #ffff00 75%, #ffa500 83%, #ff0000 91%, #800080 100%); /* FF3.6+ */<br>
background: -webkit-gradient(linear, left bottom, right top, color-stop(52%,#800080), color-stop(56%,#4b0082), color-stop(62%,#0000ff), color-stop(68%,#008000), color-stop(75%,#ffff00), color-stop(83%,#ffa500), color-stop(91%,#ff0000), color-stop(100%,#800080)); /* Chrome,Safari4+ */<br>
background: -webkit-linear-gradient(45deg, #800080 52%,#4b0082 56%,#0000ff 62%,#008000 68%,#ffff00 75%,#ffa500 83%,#ff0000 91%,#800080 100%); /* Chrome10+,Safari5.1+ */<br>
background: -o-linear-gradient(45deg, #800080 52%,#4b0082 56%,#0000ff 62%,#008000 68%,#ffff00 75%,#ffa500 83%,#ff0000 91%,#800080 100%); /* Opera 11.10+ */<br>
background: -ms-linear-gradient(45deg, #800080 52%,#4b0082 56%,#0000ff 62%,#008000 68%,#ffff00 75%,#ffa500 83%,#ff0000 91%,#800080 100%); /* IE10+ */<br>
background: linear-gradient(45deg, #800080 52%,#4b0082 56%,#0000ff 62%,#008000 68%,#ffff00 75%,#ffa500 83%,#ff0000 91%,#800080 100%); /* W3C */<br>
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#800080', endColorstr='#800080',GradientType=1 ); /* IE6-8 fallback on horizontal gradient */<br>
}<br>
</style>
</code>
<h1>Usage Examples</h1>
<h4>Example Dropdown</h4>
<div class="dd-cnt">
<div class="dd">
<div class="dd-top">
<div class="dd-selection">Choose an option</div>
<div class="dd-triangle"></div>
<div class="clear"></div>
</div>
<div class="dd-bot">
<div class="dd-item" data-value="Too Unhealthy">Bacon</div>
<div class="dd-item" data-value="Too Boring">Vanilla Ice Cream</div>
<div class="dd-item" data-value="Too Messy">Hot Cheetos</div>
</div>
</div>
</div>
<h4>Example Slider</h4>
<div class="sliderCnt">
<div class="sliderLeft"></div>
<div class="sliderRight"></div>
<div class="slider">
<img src="~/ProjectsExternals/CSSArrows/images/1.png" alt="">
<img src="~/ProjectsExternals/CSSArrows/images/2.png" alt="">
<img src="~/ProjectsExternals/CSSArrows/images/3.png" alt="">
</div>
</div>
<h4>Example Link</h4>
<a href="http://triiline.com" class="example-link">
<div class="link-text">Find out more!</div>
<div class="link-arrow"></div>
</a>
<div class="clear"></div>
<p>
Think I missed something? Know a better way of doing something?
<a target="_blank" href="https://github.com/JamesGould123/arrows">Fork me on Github!</a>
</p>
</div>
<script type="text/javascript" src="scripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="scripts/functions.js"></script>
</body>
</html>