我有一个面板,如果这个面板被选中(点击它),我把它涂成蓝色。此外,我还向该面板添加了一个小符号(.png图像),表示所选面板以前已经被选中过。

例如,如果用户看到10个面板,其中4个有这个小标志,他就知道他之前已经点击过这些面板。到目前为止,这工作得很好。现在的问题是,我不能同时显示小标志和使面板蓝色。

我将面板设置为蓝色,css背景:#6DB3F2;背景图片加上background-image: url('images/checked.png')。但是背景颜色似乎在图片上方,所以你看不到这个标志。

因此,是否可以为背景颜色和背景图像设置z-index ?


当前回答

假设你想要一个图标在右边(或左边),那么这应该是最好的工作:

.show-hide-button::after {
    content:"";
    background-repeat: no-repeat;
    background-size: contain;
    display: inline-block;
    background-size: 1em;
    width: 1em;
    height: 1em;
    background-position: 0 2px;
    margin-left: .5em;
}
.show-hide-button.shown::after {
    background-image: url(img/eye.svg);
}

您也可以使用background-size: contains;,但这应该是基本相同的。背景位置将取决于你的图像。

然后你可以很容易地在hover上做一个替代状态:

.show-hide-button.shown:hover::after {
    background-image: url(img/eye-no.svg);
}

其他回答

也可以使用下一个语法。

background: <background-color> 
            url('../assets/icons/my-icon.svg')
            <background-position-x background-position-y>
            <background-repeat>;

它允许你组合背景-颜色,背景-图像,背景-位置和背景-重复属性。

例子

background: #696969 url('../assets/icons/my-icon.svg') center center no-repeat;

你可以尝试用框影:inset

.second_info_block {
  background: url('imageURL');
  box-shadow: inset 0 0 0 1000px rgba(0,0,0,.4);
}

在MDN Web Docs中,你可以使用简写的background属性设置多个背景,也可以设置除了background-color之外的单个属性。在你的例子中,你可以像这样使用线性梯度:

background-image: url('images/checked.png'), linear-gradient(to right, #6DB3F2, #6DB3F2);

参数中的第一项(图像)将放在最上面。第二个项目(颜色背景)将放在第一个项目的下面。您还可以单独设置其他属性。例如,设置图像大小和位置。

background-size: 30px 30px;
background-position: bottom right;
background-repeat: no-repeat;

这种方法的好处是你可以很容易地在其他情况下实现它,例如,你想让蓝色覆盖图像具有一定的不透明度。

background-image: linear-gradient(to right, rgba(109, 179, 242, .6), rgba(109, 179, 242, .6)), url('images/checked.png');
background-size: cover, contain;
background-position: center, right bottom;
background-repeat: no-repeat, no-repeat;

分别设置各个属性参数。因为图像被放在颜色叠加的下面,它的属性参数也被放在颜色叠加参数之后。

很有趣的问题,还没见过。这段代码对我来说工作得很好。在chrome和IE9上进行了测试

<html>
<head>
<style>
body{
    background-image: url('img.jpg');
    background-color: #6DB3F2;
}
</style>
</head>
<body>
</body>
</html>

< style=“background-color: #ffffff;”><a href=“/<%=logo_marka_url%>”><img border=“0” style=“border-radius:5px;background:url(images/picture.jpg') 50% 50% 无重复;宽度:150px;高度:80px;” src=“images/clearpixel.gif”/></a></li>

其他样本盒中心图像和背景颜色

1.首先清除像素固定图像区域 2.样式中心图像区域框 3.李背景或div色彩风格