How to create cube with only HTML and CSS?

前端 未结 9 2090
星月不相逢
星月不相逢 2021-01-30 17:03

I have this and I want to make a cube with HTML & CSS only like in the above image. My best try:

9条回答
  •  半阙折子戏
    2021-01-30 17:49

    A single box and 2 pseudos can do this as well.

    http://codepen.io/gc-nomade/pen/vGeajp

    #square {
    
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 5px;
      background: #C52329;
      /*box-shadow: 0 0 5px;*/
      width: 90px;
      height: 150px;
      margin: 5em;
      position: relative;
      transform: skew(30deg) rotate(30deg);
    }
    
    #square:before,
    #square:after {
      display: inherit;
      align-items: center;
      justify-content: center;
      content: 'before';
      position: absolute;
      top: 0;
      left: 2px;
      right: -2px;
      bottom: 0;
      background: inherit;
      border-radius: inherit;
      box-shadow: inherit;
      transform: translate(100%, -31%) skew(0, -45deg) rotate(0deg);
    }
    #square:after {
      content: 'after';
      top: -2px;
      left: 0%;
      height: 60%;
      right: 0;
      bottom: 2px;
      transform: translate(50%, -100%) rotate(0deg)skew(-45deg)
    }
    boxe

提交回复
热议问题