Left/right transparent cut out arrow

后端 未结 4 1956
猫巷女王i
猫巷女王i 2021-01-19 04:02

I am aware this has been answered previously however that was for the bottom of a div and I cannot work out how to do it for the left and right of a div.

I am trying

4条回答
  •  隐瞒了意图╮
    2021-01-19 04:28

    It can be made with a single element using inset box-shadow and pseudo-elements :before and :after

    The elements are skewed by 45deg and -45deg to create the transparent gap. Inset box-shadow is used to increase the width of the arrow banner.

    Fiddle (1 element)

    body {
      font-size: 10px;
    }
    div {
      background: url('https://farm7.staticflickr.com/6217/6216951796_e50778255c.jpg');
      height: 33.3em;
      width: 50em;
      position: relative;
      overflow: hidden;
      box-shadow: inset 2em 0 0 0 rgba(255, 255, 255, 0.6);
    }
    div:before, div:after {
      content: "";
      position: absolute;
      left: 2em;
      background-color: rgba(255, 255, 255, 0.6);
      height: 25em;
      width: 2em;
      -webkit-transform-origin: 0% 0%;
      -moz-transform-origin: 0% 0%;
      -ms-transform-origin: 0% 0%;
      transform-origin: 0% 0%;
    }
    div:before {
      bottom: -8.35em;
      -webkit-transform: skewY(45deg);
      -moz-transform: skewY(45deg);
      -ms-transform: skewY(45deg);
      transform: skewY(45deg);
    }
    div:after {
      top: -8.35em;
      -webkit-transform: skewY(-45deg);
      -moz-transform: skewY(-45deg);
      -ms-transform: skewY(-45deg);
      transform: skewY(-45deg);
    }

    Bugs : Browser rendering of box-shadow isn't consistent when using veiwport units. On zooming-out to 33%, GC shows 1px gap b/w pseudo-element and box-shadow. This bug doesn't occur with px and em units on zooming.


    A better approach than the one given above would be to use one element on top of img element. The rest properties (overflow: hidden;, box-shadow) too are used, but this doesn't have the gap between the arrow even on zooming.

    Fiddle (2 elements)

    enter image description here


    Note :

    • Ideas used from earlier post here.
    • All measurements are done in em with a set font-size of 10px.

提交回复
热议问题