Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming that I've understood you right, you can just use the <code>background</code> property for an image:</p> <p>CSS:</p> <pre><code>#image_o1 { background: transparent url(http://davidrhysthomas.co.uk/linked/astrid_avatar.png) top left no-repeat; } </code></pre> <p>HTML:</p> <pre><code>&lt;img id="image_o1" src="http://davidrhysthomas.co.uk/linked/mask.png" /&gt; </code></pre> <p><a href="http://jsfiddle.net/davidThomas/pb4tL/1/" rel="nofollow">JS Fiddle demo</a>.</p> <p>The only major problem with this method is that it uses the masking image in the <code>src</code> of the <code>img</code> element, and puts the 'real' image in the <code>background</code>.</p> <p>If JavaScript is an option, then you could use the image you want to mask as the <code>src</code> of the image element(s), and then switch that for a mask, though this is a little messy (and could definitely be improved):</p> <pre><code>function imageMask(){ var masked = document.getElementsByClassName('masked'); var mD, mU, rImg; for (i=0; i&lt;masked.length; i++){ mD = window.getComputedStyle(masked[i],null).backgroundImage; mU = mD.substring(mD.indexOf('(')+1,mD.indexOf(')')); rImg = masked[i].src; masked[i].src = mU; /* For some (probably obvious) reason: masked[i].style.backgroundImage = rImg; refused to work, so I'm using 'setAttribute()' instead, in a hackish and hideous workaround. */ masked[i].setAttribute('style','background-image: url(' + rImg + ');'); } }; window.onload = imageMask(); </code></pre> <p><a href="http://jsfiddle.net/davidThomas/pb4tL/3/" rel="nofollow">JS Fiddle demo</a></p> <p>Browser compatibility might be a problem with the JavaScript approach, though, as IE (I think) doesn't support either <code>.getElementsByClassName()</code> <em>or</em> <code>window.getComputedStyle()</code>. The majority of other browsers, though, seem happy enough with it. Tested in Firefox 7 and Chromium 14 on Ubuntu 11.04.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload