CSS Triangle with Border

02/18/2021

Demo

Full Screen

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>CSS Triangle</title>
    <link rel="stylesheet" type="text/css" href="https://demo.plantpot.works/assets/css/normalize.css">
    <link rel="stylesheet" href="https://use.typekit.net/opg3wle.css">
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <h1>CSS TRIANGLE</h1>
      <div class="box">
        <div class="triangle-01"></div>
        <div class="triangle-02"></div>
        <div class="triangle-03"></div>
        <div class="triangle-04"></div>
      </div>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  padding: 10px;
}
h1 {
  margin: 0;
  color: #3d3935;
  font-size: 3rem;
  letter-spacing: 1px;
  text-align: center;
}
.box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 300px;
  margin-top: 20px;
}
.triangle-01 {
  border-right: 30px solid transparent;
  border-bottom: 51.962px solid #db4437;
  border-left: 30px solid transparent;
}
.triangle-02 {
  border-top: 51.962px solid #4285f4;
  border-right: 30px solid transparent;
  border-left: 30px solid transparent;
}
.triangle-03 {
  border-top: 30px solid transparent;
  border-left: 51.962px solid #f4b400;
  border-bottom: 30px solid transparent;
}
.triangle-04 {
  border-top: 30px solid transparent;
  border-right: 51.962px solid #0f9d58;
  border-bottom: 30px solid transparent;
}