2013-08-07 103 views
6

别人如何使用纹理结合作为背景图片和背景颜色纹理之上?CSS:结合纹理和色彩

这里的质地:

Texture alone

我想我的身体背景页是这样:

enter image description here

我与backroung形象和挣扎背景色:http://jsfiddle.net/87K72/

body{ 
    background: #6DB3F2 url('http://s13.postimg.org/j0qiscsw3/cream.png'); 
} 
+0

应用背景图片到你的'html'标签,应用背景色为你的'body'标签,并确保它占用了整个页面。 –

回答

7

您可以使用覆盖DIV与alpha通道你的身体顶部,但在你的其他元素下。

jsFiddle example

<h1>I want blue color above my texture</h1> 
<div id="cover"></div> 
body { 
    background: url('http://i.stack.imgur.com/oslRB.png'); 
} 
h1{ 
    position:relative; 
    z-index:2; 
} 
#cover { 
    position:absolute; 
    top:0; 
    bottom:0; 
    left:0; 
    right:0; 
    background-color:rgba(109,179,242,0.5); 
    z-index:1; 
} 
+0

哇,不知道顶/左/底/右= 0技巧得到一个拉伸的div横跨整个视口。太好了! –

+1

使用伪元素可以轻松避免#cover。 –

+0

@Rollyng:该解决方案不适用于允许向下滚动的页面:http://jsfiddle.net/87K72/4/ –

1

它看起来像你的texture here缺少一个alpha通道。它不是半透明的,它真的是白色的。

+0

你是第一个,你是对的!我把它在这里为你的知识http://subtlepatterns.com/ – Rollyng

+0

检查@ j08691解决方案有一个好的技巧(必知)尽管透明度 – Rollyng

+1

是啊,这是一个不错的把戏值的作品,但它基本上是在另一层之上具有半透明层的相同想法。这一次颜色层位于顶部。这种方法的问题在于,你必须调整颜色和alpha值才能使它恰到好处,因为使它变为半透明会使它淡化一点。如果您与设计师一起工作,或者您需要尊重固定颜色图表,最好使用提供的颜色代码。 –

1

你需要使用一个半透明的背景纹理是什么;那么你的CSS指令,将这样的伎俩:

HTML:

<h1>I want blue color above my texture</h1> 

CSS:

body { 
    background: #6DB3F2 url('http://wizzley.com/static/img/bg/texture8.png'); 
} 

例子: http://jsfiddle.net/87K72/3/

+0

检查@ j08691解决方案有一个很好的把戏(必须知道)尽管透明度的值尽管价值透明 – Rollyng

1

你可以利用CSS不透明的做到这一点。

创建两个div - 一个颜色,一个用于质地:

HTML:

<div class="texture-color"> 
    <div class="texture"> 
     <h1> I want blue color above my texture</h1> 
    </div> 
</div> 

CSS:

.texture,.texture-color { 
    position: absolute; 
    left: 0; 
    top: 0; 
    bottom: 0; 
    right: 0; } 

.texture { 
    background: #6DB3F2 url('http://s13.postimg.org/j0qiscsw3/cream.png'); 
    opacity: 0.8; } 

.texture-color { 
    background-color: cyan; } 

jsFiddle

1

http://jsfiddle.net/uyrPA/3/

body { 
    width:auto; 
    height:auto; 
    background: green; 
} 


body:after{ 
    content : ""; 
    display: block; 
    position: absolute; 
    top: 0; 
    left: 0; 
    background: url(http://i.stack.imgur.com/oslRB.png) repeat; 
    width: 100%; 
    height: 100%; 
    opacity : 0.5; 
} 

h1{ 
    position:relative; 
    z-index:2; 
} 
+0

It应该是“位置:固定”,以使这个页面需要向下滚动。另外,为应该出现在颜色层上的所有元素设置正确的Z-index是一件很乏味的事情。 –