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

How come my container-fluid div isn't encompassing the box divs too?

I am currently in the process of creating a dice using the bootstrap grid system. Although I have not completed it yet, here is a small snippet of the code that showcases my progress. However, when I inspect my webpage using developer tools (see attached i ...

Can you explain how the CSS hack *+html works?

While working on a project, I have encountered multiple rules that look like this: * + html { /.../ } Although I understand the purpose of using * and +, I am unsure about the significance of this particular construction. Additionally, I came across ...

Having trouble connecting the HTML file with the JavaScript file

This is my unique HTML file <!DOCTYPE html> <html> <head> <script src="ll.js"></script> </head> <body> <link rel="stylesheet" href="home.css"> ...

Tips for using jQuery to dynamically apply CSS styles to new content added to a webpage

I have encountered this question multiple times on stackoverflow and through google search, but unfortunately none of the suggested solutions have worked for me. My issue involves a page that loads an HTML page with empty sections, which are then dynamica ...

In Javascript, create a variable that dynamically updates for every child element

While this might appear to be a simple question, it has been troubling me for some time now. Let me elaborate on what I am trying to accomplish. I have a collection of images in a gallery, and my goal is to center each image vertically within its contain ...

The height of the image remains constant when its width is decreased, causing it not to resize proportionally

I am facing an issue with displaying images in a div of various resolutions. When I have a wide image with low height, such as 730x90, it does not show properly on mobile devices. The width shrinks but the height remains the same. Below is the code snipp ...

What is the proper usage of main.js and main.css within the skeleton portlet project that is created by the Liferay 6.0.6 plugin SDK?

Is it a good practice to include portlet-specific JS or CSS in them only if <portlet:namespace /> works within them? Should I rely on unique function/variable names or class names instead? ...

What's the best way to adjust the card column for mobile view resizing?

I am trying to modify the card view for mobile devices to display as a 2-column layout. I have adjusted the flex length and grid size in my code, but I still can't achieve the desired result. Can someone guide me on how to make this change? Current d ...

Using CSS to style PHP function results

I am working on a shopping cart application and I want to incorporate a condensed version of the cart onto my home page. The main shopping cart page is called 'modcart.php' and I have managed to integrate it into my homepage using the following c ...

Adjusting image width using jQuery

I have been experimenting with creating a Webgl hover effect for an image. The effect works well, but now I am trying to specify a width for the image within jQuery. new hoverEffect({ parent: document.querySelector('.ticket'), intensity1: 0. ...

How to Safely Swap Background Images on a Website Using CSS without Affecting the Body

How can I create a background similar to this one, but using an image instead of the blue background? Take a look at I noticed that resizing the browser window doesn't affect the background. What steps should I take to achieve this effect? ...

Issue with customizing Bootstrap5 table colors based on themes

In my latest project, I decided to customize Bootstrap 5.1.3 using Sass in order to introduce some new color themes to the panels. I quickly realized that customizing Bootstrap 5.1.3 is not as straightforward as it was with Bootstrap 4. After updating my ...

Secondary menu supersedes primary dropdown menu

Having trouble getting a vertical dropdown menu to work properly, with the submenus overriding the main menu. I've searched everywhere for a solution but can't seem to find one. Anyone out there who could help me figure this out? Here's the ...

The sticky positioning feature seems to be malfunctioning exclusively on mobile devices

I have encountered an unusual issue while working on my cafe-shop menu. Despite finding a solution in a standalone HTML file, the menu doesn't function properly when inserted into one of the pages of my WordPress theme - specifically, it only works on ...

Position your Logo to the left, align the Menu in the center, and place top links on the right using Bootstrap

I am currently struggling to create two rows with the logo aligned to the left, 'Home' and 'User' menu links at the top right corner, and a second row displaying 'Link1', 'Link2', 'Link3' menus centered. Th ...

Automatically add shimmer with CSS styling

Is it possible to make the shine effect work automatically (without needing hover) every 5 seconds? http://jsfiddle.net/AntonTrollback/nqQc7/ .icon:after { content: ""; position: absolute; top: -110%; left: -210%; width: 200%; height: 200%; ...

Highslide's Page Z-Index Elevation

Hey there, I'm currently facing an issue with the z-index positioning of an in-page gallery on my website. I attempted to use the hs.zIndexCounter attribute but unfortunately, it didn't solve the problem. Just so you know, my navigation bar has ...

Issues with the last-child selector in CSS being unresponsive

I am having trouble applying styles to the final <p> in a specific div. I would like to achieve this without introducing a new class or ID. Despite attempting to use the last-child selector, I have not been successful in accomplishing my goal. I ha ...

Original: full size responsive background images without stretchRewritten: high-quality

I have incorporated the Full page scroll feature for a website from GitHub user peachananr. You can find it here: https://github.com/peachananr/onepage-scroll My goal is to assign a resizable background image to each "page". I am using the CSS rule ' ...

Utilizing CSS to align all HTML form elements at the center

Is it possible to centrally align all form labels and input fields by using CSS? If so, what would be the approach for a form where the label text is displayed vertically above the input field? #fieldset label { display: block; } #fieldset input ...