CSS: Combine Texture and Color

こ雲淡風輕ζ 提交于 2020-01-03 10:59:11

问题


someone how to combine Texture use as background-image and Background-color above that texture ?

Here the texture :

I want my body background page to be like this :

I'm struggling with backroung-image and background-color : http://jsfiddle.net/87K72/

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

回答1:


You can use an overlay div with an alpha channel on top of your body but under your other elements.

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;
}



回答2:


It looks like your texture here lacks an alpha channel. It's not semi-transparent, it's really white.




回答3:


You could make use of css opacity to do this.

Create two divs - one for the color, and one for the texture:

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




回答4:


You need to use a semi transparent background texture for that; then your CSS directive will do the trick:

HTML:

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

CSS:

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

Example: http://jsfiddle.net/87K72/3/




回答5:


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;
}


来源:https://stackoverflow.com/questions/18105833/css-combine-texture-and-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!