Creating a torn paper illusion using CSS masking techniques

My goal is to create a ripped/lined paper effect using CSS mask. It's working well and looks good. However, I'm struggling to apply the mask at the top as well. Here's what I've 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;

If there is a better way to achieve this, please let me know. I opted for the 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>

Answer №1

To update your code, follow the instructions provided below. Please note that only the mask code will be demonstrated in this example. A random PNG image is used as a placeholder since the original SNG file may not work due to CORS issues.

Take special notice of the 50px value, which controls the size of the ripped effect.

.container{
   width: 500px;
   height: 700px;
   background-color: blue;
   -webkit-mask: 
     url('https://i.ibb.co/7RW8C9t/top.png') /*url("https://www.example.com/paper-rip-top.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.example.com/paper-rip-bottom.svg")*/
      bottom/auto 50px repeat-x;
}
<div class="container">

</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Woops! An error occurred with the message: "SassError: Could not locate the specified target selector" while working with SCSS Modules and incorporating

Currently, I am working with Next.js and utilizing SCSS Modules. To incorporate Bootstrap into my project, I opted to install it using the command npm install bootstrap. Following this installation, I went ahead and created a new file titled common.scss wi ...

Can someone point out the mistakes in my CSS Layout?

I've been struggling to make progress on this task over the past couple of days, encountering roadblocks with no clear solution in sight. The maze of nested divs I'm navigating through might be playing tricks on my mind, so having a fresh pair of ...

Spacing between table cells is only applied to the first row and footer

In an attempt to add spacing between the first row, second row, and footer of a table, I have experimented with cell spacing combined with border-collapse. However, the spacing is being applied all over the table instead of in specific areas. I am utilizin ...

What could be causing the unexpected white gap within my div element even though I've adjusted its dimensions to be minimal?

<div style=" height:0; width: 0 ; border: 1px solid black ; "> This code snippet displays a div element with a specified height, width, and border color. However, there seems to be an issue with the rendering as some st ...

Initiating CSS animation from the start

Having an issue with the "Start button" that plays both animation and background sounds. When I pause it, the animation does not stop where it left off and starts from the beginning again. I tried using animation-play-state: pause and animation-fill-mode: ...

Troubleshooting the problem of fast rotation and scrolling of text in the middle but slow movement at the end with

Currently, I am utilizing the jquery animate function for animating text while also aiming to rotate the text if a specific degree is passed. In order to achieve this, I have implemented the following code snippet: var leftCss = "-"+$('#mydiv'). ...

Getting the next sibling element with Selenium: A complete guide

Having trouble targeting a textbox after the label "First Name" in a list to enter a first name. Here's what I've tried: WebElement firstNameLocTry = driver.findElement(By.xpath("//label[text()='First Name']/following-sibling::d ...

Updating the Animation for Datepicker Closure

While using the date picker, I want it to match the width of the input text box. When closing the date picker, I prefer a smooth and single motion. However, after selecting a from and to date, the datepicker no longer closes smoothly. I have attempted sol ...

Encountered an issue while trying to reset the dropdown menu values on a Dash application when utilizing a clear button

I'm attempting to add a clear button for users to reset the values in a dropdown menu. However, when I run the application, I encounter the following error preventing me from selecting an option in the dropdown: Unable to access property 'leng ...

An error keeps popping up in the console saying "Module not found"

import React from 'react' import './sidebar.css' import logo from './images/' const sidebar = () => { return ( <div className='sideBar grid'> <div className='logoDiv flex&apo ...

"Resolving an inconsistency problem with the Vary header in Htaccess

Could someone help me identify the issues in my htaccess code? I'm encountering errors: This response is negotiated, but doesn't have an appropriate Vary header. The resource doesn't send Vary consistently. ## add vary header <IfModule ...

What is the method for utilizing the onmouseover function to emphasize a specific part of an SVG graphic?

I am attempting to create an interactive SVG map of Europe. Each country is represented by a path element, and I want the opacity of a country to change to 0.5 when it is hovered over. Despite trying to define a JavaScript function for this purpose, noth ...

Tips on using CSS to hide elements on a webpage with display:none

<div class="span9"> <span class="disabled">&lt;&lt; previous</span><span class="current numbers">1</span> <span class="numbers"><a href="/index/page:2">2</a></span> <span class="num ...

Experiencing Difficulty Retaining Checkbox State Using LocalStorage Upon Page Reload

At the moment, I have a script that automatically clicks on a random checkbox whenever the page loads or refreshes. Through localStorage, I can also view the value of the input assigned to the randomly selected checkbox. However, I'm facing an issue ...

What is the best way to handle HTML files that have the same name as folders?

I am looking to incorporate a News section on my website with the unique URL: mysite.com/news Each news article should be stored in a specific folder named "News" like this: mysite.com/news/2021 However, when I attempt to access the news.html file (witho ...

What is the best way to create a cornered button using CSS?

Is there a way to create a button using only CSS? https://i.stack.imgur.com/7mjVV.png This is the code I've come up with so far: .customButton { width: 100px; height: 100px; background: #6d1a3e; position: relative; transform: rotate(-90 ...

Achieving optimal performance with scoped CSS in Vue.js

As I work on creating a new app using VueJs, I have noticed the implementation of "css scoped" as shown below: <style scoped> .example { color: red; } </style> <template> <div class="example">hi</div> </template> ...

Starting the animation only when the slide is visible

Struggling to add animations dynamically as a HTML/CSS developer who avoids JS but uses jQuery occasionally? Sound familiar? Well, I have. Recently, I managed to create a CSS-3 animation for the images in a Bootstrap carousel. Check out the code below: ...

Captivating images paired with informative captions

I am trying to display a picture with a description inline, but I am facing some issues. While I was able to align two pictures using div block:inline, adding a description to the first picture caused it to extend in width (despite setting margin: 0 and a ...

What is the best way to style the currently selected option element in a select dropdown?

I am trying to change the font color of specific option elements within a select dropdown by adding style="color: #D4D4D4". When I apply this style directly to an option element like <option value="TEST" style="color: #D4D4D4">TEST</option>, it ...