CSS: Hintergrundbild auf Hintergrundfarbe

original title: "CSS: background image on background color"


I have panel which I colored blue if this panel is being selected (clicked on it). Additionally, I add a small sign (.png image) to that panel, which indicates that the selected panel has been already selected before.

So if the user sees for example 10 panels and 4 of them have this small sign, he knows that he has already clicked on those panels before. This work fine so far. The problem is now that I can't display the small sign and make the panel blue at the same time.

I set the panel to blue with the css background: #6DB3F2; and the background image with background-image: url('images/checked.png'). But it seems that the background color is above the image so you cannot see the sign.

Is it therefore possible to set z-indexes for the background color and the background image?

Ich habe ein Feld, das ich blau gefärbt habe, wenn dieses Feld ausgewählt ist (darauf geklickt). Zusätzlich füge ich diesem Feld ein kleines Zeichen (.png-Bild) hinzu, das anzeigt, dass das ausgewählte Feld bereits ...

Dies ist die Zusammenfassung nach der Übersetzung. Wenn Sie die vollständige Übersetzung anzeigen möchten, klicken Sie auf das Symbol "Übersetzen"

Alle Antworten
  • Translate

    You need to use the full property name for each:

    background-color: #6DB3F2;
    background-image: url('images/checked.png');

    Or, you can use the background shorthand and specify it all in one line:

    background: #6DB3F2 url('images/checked.png');

  • Translate

    For me this solution didn't work out:

    background-color: #6DB3F2;
    background-image: url('images/checked.png');

    But instead it worked the other way:

    <div class="block">

    the css:

      background-image: url('img.jpg') no-repeat;
      position: relative;
      background-color: rgba(0, 0, 0, 0.37);
      content: '';
      display: block;
      height: 100%;
      position: absolute;
      width: 100%;

  • Translate

    And if you want Generate a Black Shadow in the background, you can use the following:

    background:linear-gradient( rgba(0, 0, 0, 0.5) 100%, rgba(0, 0, 0, 0.5)100%),url("logo/header-background.png");

  • Translate

    really interesting problem, haven't seen it yet. this code works fine for me. tested it in chrome and IE9

        background-image: url('img.jpg');
        background-color: #6DB3F2;

  • Translate

    Based on MDN Web Docs you can set multiple background using shorthand background property or individual properties except for background-color. In your case, you can do a trick using linear-gradient like this:

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

    The first item (image) in the parameter will be put on top. The second item (color background) will be put underneath the first. You can also set other properties individually. For example, to set the image size and position.

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

    Benefit of this method is you can implement it for other cases easily, for example, you want to make the blue color overlaying the image with certain opacity.

    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;

    Individual property parameters are set respectively. Because the image is put underneath the color overlay, its property parameters are also placed after color overlay parameters.

  • Translate

    You can also use short trick to use image and color both like this :-

    body {
         background:#000 url('images/checked.png');

  • Translate

    Here is how I styled my colored buttons with an icon in the background

    I used "background-color" property for the color and "background" property for the image.

        .btn {
          display: inline-block;
          line-height: 1em;
          padding: .1em .3em .15em 2em
          border-radius: .2em;
          border: 1px solid #d8d8d8;
          background-color: #cccccc;
        .thumb-up {
          background: url('/icons/thumb-up.png') no-repeat 3px center;
        .thumb-down {
          background: url('/icons/thumb-down.png') no-repeat 3px center;
      <span class="btn thumb-up">Thumb up</span>
      <span class="btn thumb-down">Thumb down</span>

  • Translate

    <li style="background-color: #ffffff;"><a href="/<%=logo_marka_url%>"><img border="0" style="border-radius:5px;background: url(images/picture.jpg') 50% 50% no-repeat;width:150px;height:80px;" src="images/clearpixel.gif"/></a></li>

    Other Sample Box Center Image and Background Color

    1.First clearpixel fix image area 2.style center image area box 3.li background or div color style

  • Translate
    margin: 0px;
     padding: 0px;