BigDistance BigDistance - 3 months ago 34
CSS Question

Quadrilateral Trapezoid in CSS

Hey< I am trying to recreate this image in CSS.

enter image description here

So far I have this:

https://jsfiddle.net/mstppvwe/

HTML:

<div id="container">
<a class="page-scroll" href="#red ">
<div class="red">
<p>=FIRST-</p>
</div>
</a>
<a class="page-scroll" href="#orange">
<div class="orange">
<p>--SECOND--</p>
</div>
</a>
<a class="page-scroll" href="#blue">
<div class="blue">
<p>--- THIRDBOX ---</p>
</div>
</a>




CSS:

<div id="container">
<a class="page-scroll" href="#red ">
<div class="red">
<p>=FIRST-</p>
</div>
</a>
<a class="page-scroll" href="#orange">
<div class="orange">
<p>--SECOND--</p>
</div>
</a>
<a class="page-scroll" href="#blue">
<div class="blue">
<p>--- THIRDBOX ---</p>
</div>
</a>




I've played with borders and also tried the transform, to no avail!

The whole bar needs to be a hyperlink with an overlay of text as shown in my HTML mockup

Can someone please help. Thanks!

Answer

You can do this with :before pseudo element on each div.

#container {
  margin-left: 100px;
  width: 200px;
  right: 20px;
}
.three-bars,
.red,
.orange,
.blue {
  color: white;
  height: 50px;
  margin: 10px;
  padding: 10px;
  float: right;
  font-size: 20px;
  text-align: right;
  position: relative;
}
.red {
  width: 100px;
  background-color: #da3421;
}
.orange {
  width: 150px;
  background-color: #ec9a4c;
}
.blue {
  width: 200px;
  background-color: #5ab7c4;
}
a > div:before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 70px 70px;
  border-color: transparent transparent black;
  transform: translateX(-100%);
}
.red:before {
  border-color: transparent transparent #da3421;
}
.orange:before {
  border-color: transparent transparent #ec9a4c;
}
.blue:before {
  border-color: transparent transparent #5ab7c4;
}
<div id="container">
  <a class="page-scroll" href="#red ">
    <div class="red">
      <p>=FIRST-</p>
    </div>
  </a>
  <a class="page-scroll" href="#orange">
    <div class="orange">
      <p>--SECOND--</p>
    </div>
  </a>
  <a class="page-scroll" href="#blue">
    <div class="blue">
      <p>--- THIRDBOX ---</p>
    </div>
  </a>
</div>