Required pentagon shape with right direction CSS and HTML

前端 未结 4 1860
我寻月下人不归
我寻月下人不归 2021-02-06 02:48

How do i make this type of pentagone without -webkit-clip-path because its doesn\'t work most of the browser like Firefox, IE9.

4条回答
  •  情歌与酒
    2021-02-06 03:14

    You can use this approach :

    • Rotate the main element by 45deg. Add overflow: hidden; to it.
    • Add a pseudo-element and un-transform it. Position it correctly within the main element.

    Hover over the image to see how this works :

    FIDDLE and snippet:

    body {
      background: url(http://lorempixel.com/640/480);
    }
    div {
      height: 200px;
      width: 200px;
      -webkit-transform: rotate(-45deg);
      -moz-transform: rotate(-45deg);
      transform: rotate(-45deg);
      position: relative;
      overflow: hidden;
      top: 50px;
      left: 50px;
    }
    div:before {
      content: "";
      position: absolute;
      left: 100px;
      height: 141px;
      width: 212px;
      display: block;
      background: url(http://i.imgur.com/mI2OFTB.jpg);
      background-size: 100%;
      transform-origin: 0% 0%;
      -webkit-transform: rotate(45deg);
      -moz-transform: rotate(45deg);
      transform: rotate(45deg);
    }
    /*Just for demonstration of working*/
    
    div:hover {
      overflow: visible;
      background: rgba(25, 50, 75, 0.6);
    }

    Output :

    enter image description here

提交回复
热议问题