Peter
Peter

Reputation: 11825

Multible css Triangle effect with float left

How can i create the same "triangle" borders like on the picture with pure css?

SS

Fiddle:

CODE

/* .TEST {
      border-bottom: 169px solid red;
      border-top: 169px solid red;
      border-left: 42px solid transparent;
      border-right: 42px solid transparent;  
      height: 169px;
      width: 169px;
    } */

#d {
  width: 100%;
  font-size: 25px;
}
#d1,
#d2,
#d3 {
  width: 33%;
  float: left;
  padding: 30px;
  color: #D2B746;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  -o-box-sizing: border-box;
  box-sizing: border-box;
}
#d2 {
  width: 34%;
  color: #000;
}
.gradient_black {
  background: #303437;
}
.gradient_gold {
  background: #d4ba49;
}
<div id="d">
  <div id="d1" class="gradient_black">Test</div>
  <div id="d2" class="gradient_gold TEST">Test</div>
  <div id="d3" class="gradient_black">Test</div>
</div>

EDIT: Or should i use SVGs?

Upvotes: 1

Views: 70

Answers (2)

dippas
dippas

Reputation: 60553

using transform: skew() you can achieve this

Note: I made a few tweaks to your code

*,
*::before,
*::after {
  box-sizing: border-box;
}
body {
  margin: 0
}
#d {
  width: 100%;
  font-size: 25px;
  background: #303437;
  display: flex
}
#d1,
#d2,
#d3 {
  width: calc((100% / 3) - 6px);
  padding: 30px;
  color: #D2B746;
}
#d2.gradient_gold {
  background: #d4ba49;
  color: #000;
}
#d>div {
  transform: skew(-20deg)
}
<div id="d">
  <div id="d1" class="gradient_black">Test</div>
  <div id="d2" class="gradient_gold">Test</div>
  <div id="d3" class="gradient_black">Test</div>
</div>

Upvotes: 1

Adriano
Adriano

Reputation: 3934

you might want to use the transform: skewX() with in CSS. Reference: http://www.w3schools.com/css/css3_2dtransforms.asp (search for "skewX") Live Example: http://www.w3schools.com/css/tryit.asp?filename=trycss3_transform_skewx

Upvotes: 0

Related Questions