1

我正在尝试将背景图像放在渐变背景之上,我是否必须创建另一个 div 才能做到这一点?

#inner_bg {
    width: 846px;
    height: 646px;
    margin: -1px 0 0 0;
    background: url(../simg/inner_bg.gif) no-repeat 20px 140px;
    background: #031f34;
    background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSI5JSIgc3RvcC1jb2xvcj0iIzAzMWYzNCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjQwJSIgc3RvcC1jb2xvcj0iIzAzNjY4ZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjcwJSIgc3RvcC1jb2xvcj0iIzA1YjdkMSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
    background: -moz-linear-gradient(left,  #031f34 9%, #03668f 40%, #05b7d1 70%);
    background: -webkit-gradient(linear, left top, right top, color-stop(9%,#031f34), color-stop(40%,#03668f), color-stop(70%,#05b7d1));
    background: -webkit-linear-gradient(left,  #031f34 9%,#03668f 40%,#05b7d1 70%);
    background: -o-linear-gradient(left,  #031f34 9%,#03668f 40%,#05b7d1 70%);
    background: -ms-linear-gradient(left,  #031f34 9%,#03668f 40%,#05b7d1 70%);
    background: linear-gradient(to right,  #031f34 9%,#03668f 40%,#05b7d1 70%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#031f34', endColorstr='#05b7d1',GradientType=1 );
    float: left;
    position: relative;
}
4

2 回答 2

0

是的,您需要使用另一个元素(可能是 ::before 之类的伪元素),背景正在相互替换(当它们有效时)。

http://jsfiddle.net/fTpaz/2/

#inner_bg {
    width: 846px;
    height: 646px;
    margin: -1px 0 0 0;
    background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSI5JSIgc3RvcC1jb2xvcj0iIzAzMWYzNCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjQwJSIgc3RvcC1jb2xvcj0iIzAzNjY4ZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjcwJSIgc3RvcC1jb2xvcj0iIzA1YjdkMSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
    background: -moz-linear-gradient(left,  #031f34 9%, #03668f 40%, #05b7d1 70%);
    background: -webkit-gradient(linear, left top, right top, color-stop(9%,#031f34), color-stop(40%,#03668f), color-stop(70%,#05b7d1));
    background: -webkit-linear-gradient(left,  #031f34 9%,#03668f 40%,#05b7d1 70%);
    background: -o-linear-gradient(left,  #031f34 9%,#03668f 40%,#05b7d1 70%);
    background: -ms-linear-gradient(left,  #031f34 9%,#03668f 40%,#05b7d1 70%);
    background: linear-gradient(to right,  #031f34 9%,#03668f 40%,#05b7d1 70%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#031f34', endColorstr='#05b7d1',GradientType=1 );
    float: left;
    position: relative;
}

#inner_bg::before{
    content: ' ';
    position:absolute;
    left:0;
    right:0;
    top:0;
    bottom:0;
    background: red;
    opacity:0.5;
}​
于 2012-08-30T01:56:27.733 回答
0

创造另一个鸿沟。位于带有渐变背景的 div 顶部。添加比具有渐变背景的 div 更高的 z-index。

于 2012-08-30T02:01:45.800 回答