htmlcsscss-shapes

How to create a ribbon shape in CSS


http://jsfiddle.net/6HyjZ/

.bookmarkRibbon {
  width: 0;
  height: 100px;
  border-right: 50px solid blue;
  border-left: 50px solid blue;
  border-bottom: 30px solid transparent;
}
<div class="bookmarkRibbon"></div>

I'm struggling to make a version of this shape where the ribbon is pointing right instead of down, how can I achieve this?


Solution

  • Ribbon shape using CSS Clip Path:

    .bookmarkRibbon {
      width: 100px;
      height: 60px;
      background: blue;
      clip-path: polygon(0% 0%, 100% 0%, calc(100% - 20px) 50%, 100% 100%, 0% 100%);
    }
    <div class="bookmarkRibbon"></div>

    Pointing down:

    .bookmarkRibbon {
      width: 60px;
      height: 100px;
      background: blue;
      clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 50% calc(100% - 20px), 0% 100%, 0% 0%);
    }
    <div class="bookmarkRibbon"></div>

    Ribbon shape using CSS border

    To help you visualize the logic step-by-step, so you can apply it easily on any side:

    CSS Ribbon Shape - How To Create

    .bookmarkRibbon {
      border:       30px solid blue;        /* All borders set */
      border-left:  0;                      /* Remove left border */
      border-right: 20px solid transparent; /* Right transparent */
      width:        100px;                  /* Increase element Width */
    }
    <div class="bookmarkRibbon"></div>