[css] How do CSS triangles work?

If you want to play around with border-size, width and height and see how those can create different shapes, try this:

_x000D_
_x000D_
const sizes = [32, 32, 32, 32];_x000D_
const triangle = document.getElementById('triangle');_x000D_
_x000D_
function update({ target }) {_x000D_
  let index = null;_x000D_
  _x000D_
  if (target) {_x000D_
    index = parseInt(target.id);_x000D_
_x000D_
    if (!isNaN(index)) {_x000D_
      sizes[index] = target.value;_x000D_
    }_x000D_
  }_x000D_
  _x000D_
  window.requestAnimationFrame(() => {_x000D_
    triangle.style.borderWidth = sizes.map(size => `${ size }px`).join(' ');_x000D_
    _x000D_
    if (isNaN(index)) {_x000D_
      triangle.style[target.id] = `${ target.value }px`;_x000D_
    }_x000D_
  });_x000D_
}_x000D_
_x000D_
document.querySelectorAll('input').forEach(input => {_x000D_
  input.oninput = update;_x000D_
});_x000D_
_x000D_
update({});
_x000D_
body {_x000D_
  margin: 0;_x000D_
  min-height: 100vh;_x000D_
  display: flex;_x000D_
  justify-content: center;_x000D_
  align-items: center;_x000D_
  overflow: hidden;_x000D_
}_x000D_
_x000D_
#triangle {_x000D_
    border-style: solid;_x000D_
    border-color: yellow magenta blue black;_x000D_
    background: cyan;_x000D_
    height: 0px;_x000D_
    width: 0px;_x000D_
}_x000D_
_x000D_
#controls {_x000D_
  position: fixed;_x000D_
  bottom: 0;_x000D_
  left: 0;_x000D_
  right: 0;_x000D_
  background: white;_x000D_
  display: flex;_x000D_
  box-shadow: 0 0 32px rgba(0, 0, 0, .125);_x000D_
}_x000D_
_x000D_
#controls > div {_x000D_
  position: relative;_x000D_
  width: 25%;_x000D_
  padding: 8px;_x000D_
  box-sizing: border-box;_x000D_
  display: flex;_x000D_
}_x000D_
_x000D_
input {_x000D_
  margin: 0;_x000D_
  width: 100%;_x000D_
  position: relative;_x000D_
}
_x000D_
<div id="triangle" style="border-width: 32px 32px 32px 32px;"></div>_x000D_
_x000D_
<div id="controls">_x000D_
  <div><input type="range" min="0" max="128" value="32" id="0" /></div>_x000D_
  <div><input type="range" min="0" max="128" value="32" id="1" /></div>_x000D_
  <div><input type="range" min="0" max="128" value="32" id="2" /></div>_x000D_
  <div><input type="range" min="0" max="128" value="32" id="3" /></div>_x000D_
  <div><input type="range" min="0" max="128" value="0" id="width" /></div>_x000D_
  <div><input type="range" min="0" max="128" value="0" id="height" /></div>_x000D_
</div>
_x000D_
_x000D_
_x000D_

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to geometry

Circle button css Using atan2 to find angle between two vectors How do I compute the intersection point of two lines? Creating a triangle with for loops Plotting a 3d cube, a sphere and a vector in Matplotlib How to find the Center Coordinate of Rectangle? Evenly distributing n points on a sphere How do CSS triangles work? How to draw circle in html page? Generate a random point within a circle (uniformly)

Examples related to polygon

How do CSS triangles work? Polygon Drawing and Getting Coordinates with Google Map API v3 A simple algorithm for polygon intersection How to determine if a list of polygon points are in clockwise order? How can I determine whether a 2D Point is within a Polygon?

Examples related to css-shapes

How to create a inner border for a box in html? CSS Circle with border How to Make A Chevron Arrow Using CSS? How to make a div with a circular shape? How to make rectangular image appear circular with CSS Half circle with CSS (border, outline only) How to draw a checkmark / tick using CSS? how to draw a rectangle in HTML or CSS? CSS3 Transform Skew One Side Center Triangle at Bottom of Div