锯齿边缘与CSS中的透明背景 [英] jagged edges with transparant background in CSS

查看:706
本文介绍了锯齿边缘与CSS中的透明背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


Make a divs top and bottom border have a jagged edge

Based on the answer of @ᴀʀᴜn BᴇrtiL I was able to create something.

The problem is it doensn't look good, I can't get rid of the background color. Using no shadow is an option, but using a static single-color background is not. So how do I make it transparent?

Or is there another way? I know CSS3 can use images in the border, but I prefer CSS-code without images.

解决方案

There are several ways to achieve this (including JS and SVG solutions). However I think the easiest solution using pure CSS is using some pseudo-elements (to render the jagged edges) in combination with linear-gradient and multi-backgrounds feature. Here is the demo code:

div {
  width:200px;
  height:250px;    
  background:white;
  position:relative;
  margin-top:25px;
}
div:before, div:after {
  content:'';
  width:100%;
  height:5px;
  position:absolute;
  bottom:100%;
  left:0;
  background-image: linear-gradient(135deg, transparent 66%, white 67%),
                    linear-gradient(45deg, white 33%, gray 34%, transparent 44%);
  background-position: -5px 0;
  background-size: 10px 100%;
  background-repeat:repeat-x;
}
div:after {
  top:100%;
  bottom:auto;
  background-image: linear-gradient(135deg, white 33%, gray 34%, transparent 44%),
                    linear-gradient(45deg, transparent 66%, white 67%);    
}
body {
  background:url(http://placekitten.com/800/600);
}

Demo.

这篇关于锯齿边缘与CSS中的透明背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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