0

How do you put a (transparent) image over text to keep it from being selected? I want my students to type what they see, not just copy/paste.

I'm not worried about them viewing source and copy/pasting from there - if they're that savvy I don't need to worry about them knowing the material.

2
  • 1
    Should we guess the mark-up you're using? Commented Dec 18, 2011 at 21:05
  • 1
    Perhaps you could make the text simply unselectable? stackoverflow.com/questions/2310734/… Commented Dec 18, 2011 at 21:07

2 Answers 2

6

I don't believe that this is a great idea, and nor will it work particularly well. Also, without seeing what elements you're using, I'm going to guess, with the following:

<p>Something not to copy...<img src="path/to/image.png" /></p> 

CSS:

p { position: relative; } p img { position: absolute; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; } 

JS Fiddle demo.

A slightly easier way:

p { -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; } 

JS Fiddle demo.

A slightly more reliable way (that doesn't rely on updated/'modern' browsers, but which isn't requested in your question, as it uses JavaScript:

var paras = document.getElementsByTagName('p'); for (var i=0, len=paras.length; i<len; i++){ paras[i].onmousedown = function(){ return false; }; } 

JS Fiddle demo.

Sign up to request clarification or add additional context in comments.

2 Comments

Dang David. This is a very complete answer. Thank you very much!
Thanks, glad to have been of help. =)
0

Could this be done in a simpler way using z-index? E.g. higher z-index value for the transparent image.

It's an interesting concept you are proposing, though perhaps not 'in the spirit' of website accessibility :-)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.