html - 使丝带背景透明

标签 html css

我发现了这个很棒的丝带 CSS,我一直在用它来处理我的设计。我快到了。我遇到的唯一问题是它的设置方式,它使用最初是蓝色的“主体背景颜色”来制作色带三 Angular 形和阴影......唯一的问题是我的布局将有木质背景,因此使用颜色制作丝带是行不通的。

我希望有人能帮助我或给我一些关于如何使丝带末端透明而不是蓝色的建议。

我做了一个 jsfiddle for this issue

CSS

/*Basic reset*/
* {margin: 0; padding: 0;}

html, body {height: 100%;}

body {
    background-image: url('http://noellesnotes.com/tester/wp-content/themes/ribbons-and-clouds/img/wood_pattern.png');
    text-align: center;
}

.container{
  width:564px;
  height: 500px;
  background: #FFFFFF;
  background-image: url('http://noellesnotes.com/tester/wp-content/themes/ribbons-and-clouds/img/paper_fibers.png');
  margin: 20px auto 20px;
  box-shadow: 3px 3px 3px #555555;
}

h1 {
    display: inline-block;
  width: 600px;
    font-size: 14px;
    line-height: 28px;
    color: #8699A0;
    text-shadow: 0 0 1px #758890;
    margin: 10px 0;
    font-family: arial, verdana;
    outline: none;
    padding: 14px 30px;
    position: relative;
    text-transform: uppercase;
    /*A little shadow for 3d effect*/
    /*Finally another shadow to negate some aspects of the :after element to complete the effect. This drops a shrinked shadow over the :after element with the same color like that of the background. The shadow is shrinked by the same offset amount = 18. And it is moved down by twice the offset amount to cover the entire height of the :after element*/
    box-shadow: 
        0 0 30px 0 rgba(0, 0, 0, 0.1), 
        0 36px 0 -18px #B1E3E2;
}

/*The ribbon ends*/
h1:before {
    content: '';
    position: absolute;
    top: 18px;
    left: -15%;
    z-index: -1;
    width: 130%;
    /*We will be using the triangle logic - 2 sided borders and 0 height. That will create negative triangles on the left and right*/
    height: 0;
    border: 28px solid rgba(0, 0, 0, 0);
    border-left: 28px solid #B1E3E2;
    border-right: 28px solid #B1E3E2;
    /*Same color as the container which is the body in this case*/
}

/*The after pseudo element will negatve the bottom part of the ribbon completing the effect*/
h1:after {
    content: '';
    width: 100%;
    height: 0;
    position: absolute;
    top: 100%; left: 0;
    z-index: -1;
    /*The height of the top border is same as width of the left/right borders for the smoothest effect. The height of the top border is also the same as the offset the :before element has from the top*/
    border-top: 18px solid #99acb2;
    border-left: 18px solid transparent;
    border-right: 18px solid transparent;
}

h1, h1:before {
    /*Some cool multi-background - we will use a combination of 4 backgrounds to create a cool effect*/
    background-image: 
        /*2 grey borders*/
        linear-gradient(
            transparent 8%, 
            rgba(0, 0, 0, 0.1) 8%, 
            rgba(0, 0, 0, 0.1) 14%, 
            transparent 14%, 
            transparent 86%, 
            rgba(0, 0, 0, 0.1) 86%, 
            rgba(0, 0, 0, 0.1) 92%, 
            transparent 92%
        ), 
        /*white gloss gradient*/
        linear-gradient(
            rgba(255, 255, 255, 0.75), 
            rgba(255, 255, 255, 0) 
        ), 
        /*thin stripes*/
        linear-gradient(
            45deg, 
            transparent 40%, 
            rgba(0, 0, 0, 0.1) 40%, 
            rgba(0, 0, 0, 0.1) 60%, 
            transparent 60%
        ), 
        /*white base*/
        linear-gradient(#7ED3F6, #7ED3F6); 
    background-size: 
        cover, /*borders*/
        cover, /*white gloss*/
        4px 4px, /*thin stripes*/
        cover; /*base white*/
}

h1, h1:before, h1:after {
    box-sizing: border-box;
    /*Fix to make the borders appear on the ribbon ends also*/
    background-origin: border-box;
}

提前致谢!

最佳答案

不幸的是,您需要尝试以不同的方式制作这条丝带。您将不断遇到的问题是背景(您的渐变)将始终位于您创建的边框切口下方,因此使这些透明仅显示渐变。除了使用 css 掩码(仅实验性地由 webkit 浏览器支持)之外,您必须预先组合很多这些元素,或者查看 Canvas 元素,或者可能是 SVG。您可以查看 -webkit-mask-image: url('...your image...'),但正如我所说,它几乎没有浏览器支持。

关于html - 使丝带背景透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17910516/

相关文章:

html - 是否允许在 html 文档中有一个自关闭的 div 标签?

jquery改变表格单元格颜色

html - css 圆 Angular div 在 IE8 上不工作

javascript - 使用 pdf.js 查看器打开外部文件

c# - 将外部页面加载到我的网页中更改布局

jquery - 如何删除输入字段布局

css - jQuery Mobile 滑动 li 来检查隐藏的复选框

html - CSS动画——让图片一张一张淡入淡出

html - 工作 CSS 定位不依赖于屏幕尺寸

css - 当鼠标悬停在不同的元素上时,如何显示跨度标签内的文本?