|
| 1 | +# Borders |
| 2 | + |
| 3 | +## ✔ Simple CSS |
| 4 | + |
| 5 | +```css |
| 6 | +:root { |
| 7 | + --width: 300px; |
| 8 | + --height: 100px; |
| 9 | + --top-color: #f44336; |
| 10 | + --bottom-color: #2196F3; |
| 11 | +} |
| 12 | + |
| 13 | +.separator { |
| 14 | + width: 0; |
| 15 | + height: 0; |
| 16 | + border-style: solid; |
| 17 | + border-width: var(--height) var(--width) 0 0; |
| 18 | + border-color: var(--top-color) var(--bottom-color) transparent transparent; |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +###### Reversed |
| 23 | + |
| 24 | +```css |
| 25 | +.separator.reverse { |
| 26 | + border-width: var(--height) 0 0 var(--width); |
| 27 | + border-color: var(--top-color) transparent transparent var(--bottom-color); |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +###### Vertical |
| 32 | + |
| 33 | +```css |
| 34 | +.separator.vertical { |
| 35 | + border-width: var(--height) var(--width) 0 0; |
| 36 | + border-color: var(--left-color) var(--right-color) transparent transparent; |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +###### Reversed Vertical |
| 41 | + |
| 42 | +```css |
| 43 | +.separator.vertical.reverse { |
| 44 | + border-width: 0 var(--width) var(--height) 0; |
| 45 | + border-color: transparent var(--left-color) var(--right-color) transparent; |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +- 👎 Cannot be used with percentage measurement unit _(`%`)_, any other unit is valid: _(`cm`, `em`, `ex`, `in`, `mm`, `pc`, `pt`, `px`)_ |
| 50 | +- 👎 For use in a full width or height scenarios matching the viewport, use viewport units: _(`vw`, `vh`, `vmin`)_ |
| 51 | +- 👎 Further control is limited |
| 52 | + - example: creating a shadow effect using `box-shadow` |
| 53 | +- 👍 The angle is controlled by the element height value |
| 54 | +- 👋 The example above uses [CSS Variables][css-vars] for demonstration purposes, adjust for your own use |
| 55 | + - _css variables are [not fully supported yet][css-vars-compat]._ |
| 56 | +- 👋 `reversed` & `vertical` variants listed above are verbose for demonstration purposes |
| 57 | + - for simple multi directional classes, use the [`rotate()`][css-transform-rotate] function as needed |
| 58 | + - _see [`style.css`](style.css) for an example_ |
| 59 | +- 👌 Use with `transparent` colors _(e.g. to overlay an image, or content)_ will require `absolute` or manual positioning: |
| 60 | + - _see [`layout.css`](../layout.css) for an example_ |
| 61 | + |
| 62 | +## ✔ Generated Content |
| 63 | + |
| 64 | +Can be used with the `::before` and `::after` pseudo-elements to generate HTML content for the separator without directly modifying your DOM. |
| 65 | + |
| 66 | +###### Example |
| 67 | + |
| 68 | +```css |
| 69 | +section { |
| 70 | + ... |
| 71 | +} |
| 72 | + |
| 73 | +section::after { |
| 74 | + content: ''; |
| 75 | + display: block; |
| 76 | + width: 0; |
| 77 | + height: 0; |
| 78 | + border-style: solid; |
| 79 | + border-width: 50px 300px 0 0; |
| 80 | + border-color: yellow black transparent transparent; |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +## ✔ Cross Browser Support |
| 85 | + |
| 86 | +[Supported on all browsers](http://caniuse.com/#search=border-color) |
| 87 | + |
| 88 | +## ❓ Performance |
| 89 | + |
| 90 | +> **TODO** |
| 91 | +
|
| 92 | +## Demo |
| 93 | + |
| 94 | +View [Demo][demo], Play on [CodePen][pen], or inspect the [source files](index.html). |
| 95 | + |
| 96 | +[demo]: https://raw.githack.com/ahmadnassri/css-diagonal-separators/master/borders/index.html |
| 97 | +[css-vars]: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables |
| 98 | +[css-vars-compat]: http://caniuse.com/#search=variables |
| 99 | +[css-transform-rotate]: https://www.w3.org/TR/css-transforms-1/#funcdef-rotate |
| 100 | +[pen]: http://codepen.io/ahmadnassri/pen/eBabKo |
0 commit comments