csscss-mask

Ripped paper effect with css mask


I try to achieve some ripped/lined paper effect with css mask. It works actually pretty fine and looks good. What i can't achieve is if i also want the mask at the top. So here is what i tried so far:

mask-image: linear-gradient(white, white), url("https://www.isorauschen.at/ripped-paper.svg"), url("https://www.isorauschen.at/ripped-paper-mirrored.svg");
mask-position: bottom, top;
mask-repeat: repeat-x, repeat-x;
mask-size: 400px auto, 400px auto;

Maybe there is a better way to get this done. I chose mask because it also clips all the background and other lines.

*,
*::after,
*::before {
  box-sizing: border-box;
}

.lined-paper{
    color: black;
    display: inline-block;
    line-height: calc(1.5rem + 2px);
    margin: 30px calc(1em + 5px) 0 calc(1em + 5px);
    position: relative;
  width: 400px;
}

.lined-paper-background{
    background: repeating-linear-gradient(#FBFCF8, #FBFCF8 1.5rem, #9198e5 calc(1.5rem + 1px), #9198e5 calc(1.5rem + 2px));
    background-color: #FBFCF8;
    height: 100%;
    left: 0;
    mask-composite: exclude;
    mask-composite: xor;
    mask-image: linear-gradient(white, white), url("https://www.isorauschen.at/ripped-paper.svg");
    mask-position: bottom;
    mask-repeat: repeat-x;
    mask-size: 400px auto;
    position: absolute;
    top: 0;
    width: 100%;
}

.lined-paper-title {
    align-items: end;
    background-color: #FBFCF8;
    display: flex;
    height: calc((1.5rem + 2px) * 3 - 2px);
    margin-bottom: calc(1.5rem + 4px);
    overflow: hidden;
    padding: calc(1.5rem + 2px) 3em 0 4.5em;
    position: relative;
    max-width: 100%;
}
.lined-paper-title::after,
.lined-paper-title::before {
    border-right: 1px solid pink;
    content: "";
    display: block;
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    width: 4em;
}
.lined-paper-title::before{
    border-left: 1px solid pink;
    border-right: none;
    left: auto;
    right: 0;
    width: 2em;
}

.lined-paper-title span{
    font-size: 1.5em;
    font-weight: bold;
    max-height: calc((1.5rem + 2px) * 2 - 2px);
}

.lined-paper-text {
 padding: 0 3rem 4rem 4.5rem;
 position: relative;
}

.lined-paper .masking-tape::after,
.lined-paper .masking-tape::before{
  background: rgba(255, 255, 245, 0.6);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  content: "";
  display: block;
  height: 30px;
  margin: auto;
  position: absolute;
  width: 100px;
    z-index: 3;
}

.lined-paper .masking-tape::before{
    left: -1em;
    top: calc(-1em - 5px);
    transform: rotate(-9deg);
}

.lined-paper .masking-tape::after{
    right: -1em;
    top: calc(-1em - 2px);
    transform: rotate(4deg);
}

.correction-margin-left,
.correction-margin-right{
    border-right: 1px solid pink;
    display: block;
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    width: 4em;
}
.correction-margin-right{
    border-left: 1px solid pink;
    border-right: none;
    left: auto;
    right: 0;
    width: 2em;
    z-index: 1;
}

.correction-margin-left::after,
.correction-margin-left::before{
  background-color: white;
    border-radius: 50%;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset;
    content: "";
    display: block;
    height: 20px;
    left: 50%;
    position: absolute;
    top: 20%;
    transform: translateX(-50%);
    width: 20px;
}
.correction-margin-left::before{
    bottom: 20%;
    top: auto;
}
<div class="lined-paper">

  <div class="lined-paper-background">
    <div class="correction-margin-left"></div>
    <div class="correction-margin-right"></div>
  </div>
  
  <div class="masking-tape"></div>
  
  <div class="lined-paper-title">
    <span>Lorem Ipsum Lorem Ipsum</span>
  </div>
  <div class="lined-paper-text">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  </div>
</div>


Solution

  • Update your code like below. For the sake of the demo I am showing only the mask code. I am also using a random PNG image because your SNG won't work in the snippet due to some CORS issues.

    Note the use of 50px which the value that allow you to control the size of the ripped effect

    .box{
       width: 400px;
       height: 600px;
       background-color: red;
       -webkit-mask: 
         url('https://i.ibb.co/7RW8C9t/top.png') /*url("https://www.isorauschen.at/ripped-paper.svg")*/
           top   /auto 50px repeat-x,
         linear-gradient(white, white) no-repeat
           center/100% calc(100% - 2*50px),
         url('https://i.ibb.co/5WvbqgG/zmylJ.png') /* url("https://www.isorauschen.at/ripped-paper-mirrored.svg")*/
          bottom/auto 50px repeat-x;
    }
    <div class="box">
    
    </div>