Rory
Rory

Reputation: 852

How to make a trapezium with a border

I have tried to build a trapezium which has a Text-Content and a Border (white 1px line).

I found the examples with something like this:

height: 0;
width: 120px;
border-bottom: 120px solid #ec3504;
border-left: 60px solid transparent;
border-right: 60px solid transparent;

This is a png example, if i use this as background with transpartent color it would work but is kind of a hack and not as nice...

example

"clip-path" seems to be not supported enough, so are there other ways? would SVG be a possibility?

Thanks in Advance

Upvotes: 2

Views: 1858

Answers (1)

Nenad Vracar
Nenad Vracar

Reputation: 122087

You can use pseudo-element and use perspective on parent to create that shape as background.

body {
  background: lightblue;
}
div {
  width: 150px;
  height: 40px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  -webkit-perspective: 130px;
  perspective: 130px;
  margin: 50px;
}
div:after {
  position: absolute;
  width: 100%;
  height: 100%;
  background: lightgreen;
  border: 1px solid white;
  content: '';
  left: 0;
  top: 0;
  z-index: -1;
  -webkit-transform: rotateX(20deg) rotateY(0deg);
  transform: rotateX(20deg) rotateY(0deg);
}
<div>Some text</div>

Upvotes: 6

Related Questions