How to show a background image over foreground image using CSS

Raj Kumar

I want to set the background image so that it appears in front of foreground image.

I tried the following code but it is not working as I expected:

.background-image
  {
      border :0px;
      background-image: url(/images/icon.png);  
      z-index:1000;      
  }
  .foreground-image
  {
      width:200px;
      height:113px;
      border :0px;
      z-index:1;
  }

<div>
    <a href="#" class="background-image">
        <img class="foreground-image" src="./images/pic1.jpg"  />            
    </a>
</div>

I am using CSS2.

Marc Audet

Here is one way to do it.

If this is your HTML:

<div>
    <a href="#" class="background-image">
        <img class="foreground-image" src="http://placekitten.com/200/100"/>  
    </a>
</div>

apply the following CSS rules:

div {
    border: 1px dotted blue;
}
.background-image {
    border: 1px dotted red;
    background-image: url(http://placekitten.com/200/50);
    background-position: center left;
    background-repeat: repeat-x;
    display: block;
    width: 500px;
}
.foreground-image {
    vertical-align: top;
    width: 200px;
    border: 0px;
    position: relative;
    z-index: -1;
}

Set position: relative on the image and throw the image deeper into the stacking order by using z-index: -1.

See demo at: http://jsfiddle.net/audetwebdesign/HUK28/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make a foreground image using CSS?

From Dev

How to make a foreground image using CSS?

From Dev

How to insert an image over a background image using html? But it should be responsive

From Dev

How to create a background and foreground image which overlaps?

From Dev

Using a background image CSS

From Dev

How to show foreground image and then hide on hover?

From Dev

CSS set image background color, not show image

From Dev

How to add Button over image using CSS?

From Dev

Moving a foreground image with CSS

From Dev

Moving a foreground image with CSS

From Java

How to combine Background Image + Linear Gradient in CSS ? Linear Gradient over the Background Image

From Dev

How to show text over image?

From Dev

How to show background image once?

From Dev

How to show an background image until the image loads

From Dev

How to show an background image until the image loads

From Dev

Cannot blend image with foreground and background

From Dev

Creating a transparent CSS triangle over a background image

From Dev

Creating a transparent CSS triangle over a background image

From Dev

Overlay image using css over background image which has fixed aspect ratio

From Dev

Merge background image using CSS

From Dev

How to show an image in the background when using HTTP Basic Authentication with PHP

From Dev

How do you hide and show a background image using a carousel?

From Dev

How to show an image in the background when using HTTP Basic Authentication with PHP

From Dev

Background css image won't show in firefox

From Dev

How to center an image over another image in CSS

From Dev

How to darken the background image in CSS?

From Dev

How to darken a CSS background image?

From Dev

How to set a background image in css?

From Dev

How to set background image in css

Related Related

  1. 1

    How to make a foreground image using CSS?

  2. 2

    How to make a foreground image using CSS?

  3. 3

    How to insert an image over a background image using html? But it should be responsive

  4. 4

    How to create a background and foreground image which overlaps?

  5. 5

    Using a background image CSS

  6. 6

    How to show foreground image and then hide on hover?

  7. 7

    CSS set image background color, not show image

  8. 8

    How to add Button over image using CSS?

  9. 9

    Moving a foreground image with CSS

  10. 10

    Moving a foreground image with CSS

  11. 11

    How to combine Background Image + Linear Gradient in CSS ? Linear Gradient over the Background Image

  12. 12

    How to show text over image?

  13. 13

    How to show background image once?

  14. 14

    How to show an background image until the image loads

  15. 15

    How to show an background image until the image loads

  16. 16

    Cannot blend image with foreground and background

  17. 17

    Creating a transparent CSS triangle over a background image

  18. 18

    Creating a transparent CSS triangle over a background image

  19. 19

    Overlay image using css over background image which has fixed aspect ratio

  20. 20

    Merge background image using CSS

  21. 21

    How to show an image in the background when using HTTP Basic Authentication with PHP

  22. 22

    How do you hide and show a background image using a carousel?

  23. 23

    How to show an image in the background when using HTTP Basic Authentication with PHP

  24. 24

    Background css image won't show in firefox

  25. 25

    How to center an image over another image in CSS

  26. 26

    How to darken the background image in CSS?

  27. 27

    How to darken a CSS background image?

  28. 28

    How to set a background image in css?

  29. 29

    How to set background image in css

HotTag

Archive