milk
milk

Reputation: 434

CSS perspective shape border

I have a trapezoid, made with CSS. The issue I'm having is with the line thickness of the bottom line. I've tried adding a solid border around the shape, but the bottom line is still a few pixels thinner.

Here's the fiddle showing the trapezoid: http://jsfiddle.net/d7fuaur1/

.trap { 
    width: 436px;
    height: 150px;
    position: absolute;
    padding: 0px;
    left: 100px;
    text-transform:uppercase;
    text-align:center;
    padding-top:25px; 
    padding-bottom:25px;
    top: 20px;
}

.trap:before {
    content: "";
    position: absolute;
    border-radius: 2px;
    box-shadow:0 0 0px 4px #000;
    top: -4%; bottom: -11%; left: -3%; right: -3%;
    -webkit-transform: perspective(50em) rotateX(-30deg);
    transform: perspective(50em) rotateX(-30deg);
}

What can I do to get the border thickness the same all around?

Upvotes: 2

Views: 993

Answers (3)

Jon Tan
Jon Tan

Reputation: 1551

To be honest, I'm not exactly sure how this worked

In .trap:before

Change

box-shadow:0 0 0px 4px #000;

to

box-shadow:0 1px 0px 4px #000;

I just added 1px to your v-shadow field.

[EDIT] Here's the jsfiddle for the fix.

Upvotes: 5

Giannis Grivas
Giannis Grivas

Reputation: 3412

Try this css (and check the codepen demo : http://codepen.io/ChrisPlz/pen/vjkeq)

div {
  border-top:80px solid #C1C1C1;
  border-left:45px solid transparent;
  border-right:45px solid transparent;
  padding:0 8px 0 0;
  height:0;
  width:120px;
  position: relative;
  margin: 2em auto;
  &:before {
    border-top:90px solid #000;
    border-left:50px solid transparent;
    border-right:50px solid transparent;
    padding:0 8px 0 0;
    height:0;
    width:130px; 
    position: absolute;
    top: -85px;
    left: -55px;
    content: "";
    z-index: -1;
  }
}

Upvotes: 0

newbie
newbie

Reputation: 468

You can try adding border: <size> solid <color> to .trap:before

  .trap:before {
      content: "";
      position: absolute;
      border-radius: 2px;
      box-shadow:0 0 0px 4px #000;
      top: -4%; bottom: -11%; left: -3%; right: -3%;
      z-index: ;
     -webkit-transform: perspective(50em) rotateX(-30deg);
      transform: perspective(50em) rotateX(-30deg);
      border: 5px solid black;
    }

Updated Fiddle

Upvotes: 0

Related Questions