Files
30-seconds-of-code/snippets/triangle.md
Isabelle Viktoria Maciohsek 2487083cf1 Bake dates into snippets
2021-06-13 19:41:39 +03:00

28 lines
801 B
Markdown

---
title: Triangle
tags: visual,beginner
firstSeen: 2018-02-25T15:14:39+02:00
lastUpdated: 2021-01-07T23:52:15+02:00
---
Creates a triangular shape with pure CSS.
- Use three borders to create a triangle shape.
- All borders should have the same `border-width` (`20px`).
- The opposite side of where the triangle points towards (i.e. top if the triangle points downwards) should have the desired `border-color`, whereas the adjacent borders (i.e. left and right) should have a `border-color` of `transparent`.
- Altering the `border-width` values will change the proportions of the triangle.
```html
<div class="triangle"></div>
```
```css
.triangle {
width: 0;
height: 0;
border-top: 20px solid #9C27B0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
}
```