是否可以在图片的边缘上产生撕纸效果? [英] Is it possible to make a torn paper effect on edges of a picture?

查看:66
本文介绍了是否可以在图片的边缘上产生撕纸效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新3

我更新了和其他东西进行了此操作.我找到了要应用边框的div,并使用:before :after 添加边框,如下所示.同样,我在Photoshop中制作的图像,但是这次是白色>撕边>透明而不是彩色.

要添加到底部:

  .targetdivclass:after {内容:" ";显示:块;高度:45像素;background-image:url('https://ecorelos.com/wp-content/uploads/2020/04/torn-border2.png');位置:绝对;底部:-15px;宽度:300%;左:-500px;} 

要添加到顶部(请注意,除非您也想在CSS中进行变换/旋转,否则您需要图像的翻转版本):

  .targetdivclass:before {内容:" ";显示:块;宽度:300%;高度:65像素;background-image:url('https://ecorelos.com/wp-content/uploads/2020/04/torn-border2upside.png');位置:绝对;边距顶部:-80px;左:-500px;z-index:1;} 

调整 height bottom width left 以适合图像和网站.请注意,如果将此值应用于页脚,则可能导致宽度大于100%的问题,在这种情况下,您需要将 left 保持为零.

这是响应性的,但是如有必要,您可以使用媒体查询为移动设备指定不同的大小和边距.

结果与最初要求的效果相同:

Update 3

I updated the code (http://codepen.io/anon/pen/VYRJLp) and now the edges look really like torn paper effect. It uses SVG by the way.

The only problem is I don't know how to make the image as the background of the svg AT THE SAME TIME maintain the torn-paper-like edges.

Please have a look it. Any efforts are appreciated.


Update 2

It seems that it is impossible to achieve this effect without the help of PhotoShop(PS), so I would like to add PS as a part of solution.

I am not a PS expert, but from a quick thought, I think there are a few steps I need to do:

  • Use PS to create a torn paper "shell", let's say it's shell.png It should only have color on its edges and the color should be white; the inner area is transparent, so that we can place the picture in it.
  • Place shell.png on top of the picture, let's say banner.jpg, which means set the z-index of the div which uses shell as its background image to 1.
  • Use another div to contain the banner.jpg and set the z-index below the shell div.

Questions for this approach:

  • Is it responsive?

  • If not, is it possible to make it responsive? As I have to make it work properly on mobile devices.


I remember that I saw a beautifully designed website, there is a picture in the background and the edges of this picture look like torn paper effect which is fantastic!

I searched the similar questions here but it turns out that the effects in the answers are primitive, which are very simple rugged black lines.

What I want:

  1. I want this picture to be as wide as the device screen which means responsive.
  2. The edges of this picture look like torn paper.
  3. I will place this picture as a banner after the Top Navigation bar but before the content.

It should look like the white area in this picture. But in my case, I will need to fill in my picture to replace the white area.

Here is my code: Notice: in this code, the css uses an image as the edge, BUT that is not want I want. I just want the edges to be pure CSS effects.(Is this possible?) So it will look like this one(the one on the right side, you can see that there is no white rugged edges)

<div class="row">
    <div id="letter" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">

    </div>
</div>

#letter { /*torn paper border*/
    height:450px;
    position:relative;
    top:0;
    bottom:0;
    left:0;
    right:0;
    background-image:url('img/background.jpg');
    background-size:cover;
    opacity:0.8;
    border-style: solid; 
    border-width: 40px 40px 40px; 
       -moz-border-image: url('http://news.unchealthcare.org/images/backgrounds/paper.jpg') 80 80 80 repeat; 
    -webkit-border-image: url('http://news.unchealthcare.org/images/backgrounds/paper.jpg') 80 80 80 repeat; 
         -o-border-image: url('http://news.unchealthcare.org/images/backgrounds/paper.jpg') 80 80 80 repeat; 
            border-image: url('http://news.unchealthcare.org/images/backgrounds/paper.jpg') 80 80 80 repeat;
}


Update

I think I found something quite similar to what I am imagine. Here is the effect I want:

解决方案

I was able to do this with CSS using border image slicing.

Here's the code:

body {
    background-image: url("https://i.postimg.cc/jdRfmPxv/1-2-OKX1nhs-Z3-CB2-Cid-Edh-Jw.png");
}
.border {
  border-width: 20px 0 20px 0;
  border-style:solid;
  border-image: url(https://i.postimg.cc/DZYqPDTD/bordernew.png) 50 0 50 0 repeat;
  -webkit-border-image: url(https://i.postimg.cc/DZYqPDTD/bordernew.png) 50 0 50 0 repeat;
  -moz-border-image: url(https://i.postimg.cc/DZYqPDTD/bordernew.png) 50 0 50 0 repeat;
  border-image-slice: 50 0 50 0 fill;
  border-image-width: 20 0 20 0;
  width: 100%;
  height: 60px;
}
.p {
  font-weight: bold;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

<div class="border" style="text-align:center;">
  <br />
  <span class="p">Coming soon...</span>
  <br />
  <br />
</div>

This gives me a height re-sizing div that always has the torn paper effect along the top and bottom. It's great for full width, but I wasn't able to figure out a decent way of doing the side edges at the same time as the top and bottom (easy to do the side edges if the top and bottom edges are straight).

I made the image in Photoshop - it's basically yellow in the middle, then torn and then transparent on the outer.

If you're not familiar with image slicing, the four numbers basically define (in order): the height in pixels of the top of the image that you want to use as the top border strip, the width in pixels for the right strip, then the bottom strip, then the left strip. The fill tells it to take the center part (which is discarded by default) and use it to fill the div between the borders.

Depending on your preferences you can have the border repeat (and get cut off at the end), round (repeat to the nearest number of full repetitions, which either compresses or stretches depending on which number it is nearer to) or stretch (stretches... although that distorts the image for this example).

It took some fiddling for me to get it to work correctly but I'm chuffed with the results. I couldn't find anyone with the same answer so thought I'd post it.

UPDATE

This feature IS supported in IE11 provided border-style:solid is specified. I use media queries to provide an alternative (shadows etc.) for IE10 and below where border-image is not supported (example on my website).

UPDATE 04/2020

It's now 2020 and it's been a few years since my original answer (I've learned a lot in 5 years). I recently did this on another project for wooden watches and stuff using a simpler method. I find the div I want to apply the border to and use either :before or :after to add the border as below. Again, the image I made in Photoshop but this time it's white > torn edge > transparent rather than coloured.

To add to the bottom:

.targetdivclass:after{
     content:" ";
     display:block;
     height: 45px;
     background-image:url('https://ecorelos.com/wp-content/uploads/2020/04/torn-border2.png');
     position:absolute;
     bottom:-15px;
    width:300%;
left:-500px;    
}

To add to the top (note that you need a flipped version of the image unless you want to transform/rotate it in CSS as well):

    .targetdivclass:before{
        content:" ";
     display:block;
     width:300%;
     height: 65px;
     background-image:url('https://ecorelos.com/wp-content/uploads/2020/04/torn-border2upside.png');
     position:absolute;
     margin-top:-80px;
     left:-500px;
       z-index:1;
}

Adjust the height, bottom, width and left to suit the image and the website. Note that if you apply this to the footer you can cause issues having a width greater than 100%, in which case you need to keep the left at zero.

This is responsive, but you can use media queries to specify different sizes and margins for mobile if necessary.

The result is the same effect that was originally requested:

这篇关于是否可以在图片的边缘上产生撕纸效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆