Search code examples
htmlcssborder

Is there a simple way to make a custom border shape for an HTML <div>?


I am building a webpage with cards arranged in a grid.

However, I would like my cards to have a unique shape, rather than just being rectangles. The shape I would like them to be is the shape of a manilla folder (pictured below)

Is there any relatively simply way to make a div with this shape?

folder


Solution

  • Here is a start using only html and css:

    body {
      padding: 50px;
    }
    
    div {
      position: relative;
      z-index: 1;
      white-space: nowrap;
    }
    
    div .slant {
      position: relative;
      display: inline-block;
      color: inherit;
      text-decoration: none;
      margin: 0 -14px -4px;
      width: 40px;
    }
    
    div .slant::before,
    main {
      border: 0.2em solid #000;
      background: #000;
    }
    
    div .slant::before {
      content: "";
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0.5em;
      left: 0;
      z-index: -1;
      border-bottom: none;
      border-radius: 5px 5px 0 0;
      background: #000;
      transform: perspective(5px) rotateX(2deg);
      transform-origin: bottom;
    }
    
    div.left .slant {
      padding: 1.5em 2em 1em 1em;
    }
    
    div.left .slant::before {
      transform-origin: bottom left;
    }
    
    main {
      display: block;
      margin: -8px 0 30px -14px;
      padding: 1em;
      border-radius: 0 5px 5px 5px;
      width: 200px;
      height: 300px;
    }
    <div class="left">
      <div class="slant"></div>
    </div>
    <main>
    </main>