0

Is it possible to put an image (a pattern) over 2 or more elements (with different background)? (something like Pattern Fill in Adobe Photoshop)

Here's a screenshot: enter image description here

Note: Elements content should be selectable by users. I don't want an div which is over on other elements.

mrdaliri
  • 6,594
  • 21
  • 67
  • 101

1 Answers1

0

Make a .png file (or .gif if you prefer that) and simply overlay this over the div you would like to have this pattern.

You need to set the parent element using position relative then use position absolute on the element you want to position. So if you want it to be positioned based on the table you need to add position: relative to the table (which won't do anything because it is already positioned relative) and position: absolute to the overlay. Absolute positioning takes the element out of the document flow and relative positioning leaves it in the document flow which is why stuff is being moved around. The reason for this is based off how CSS works: http://www.w3schools.com/css/pr_class_position.asp

relative The element is positioned relative to its normal position, so "left:20" adds 20 pixels to the element's LEFT position

absolute The element is positioned relative to its first positioned (not static) ancestor element

Source: Position overlay div

Code example:

<div class="overlay">
    <div class="overlay-content">
    </div>
    Content goes here
</div>

And for the css:

div.overlay{
    position: relative;
}

div.overlay-content{
    position: absolute;
    top: 0;
    left :0;
    width: 100%;
    height: 100%;
    background: url(path/to/image.png) repeat top left;
    pointer-events:none; /* To be able to click through */
}

About the click trough, have a look at this answer: Click through a DIV to underlying elements

Community
  • 1
  • 1
Jelmer
  • 2,638
  • 2
  • 25
  • 42
  • @it's your code: http://jsfiddle.net/C3Pkr/1/ .. (i changed background image to color and add an opacity to be like a transparent background image).. but content isn't selectable by user. for example, "Link #1" can't be clicked. – mrdaliri Dec 25 '12 at 12:50
  • Add the property `pointer-events:none;` I'll update my post. http://stackoverflow.com/questions/3680429/click-through-a-div-to-underlying-elements – Jelmer Dec 25 '12 at 13:05