David Thomas's answer is perfect for line numbers. More generally, if you have other text you don't want to be copied, you can have it as generated content:
<style>#uniqueid::before { content: 'TEXT GOES HERE'; }</style>
<span id="uniqueid"></span>
But it's ugly to have to embed text in your CSS, so you can refine this using CSS attr()
to read the text from an attribute in the HTML (as suggested by pimvdb):
<style>[data-nocopy]::before { content: attr(data-nocopy); }</style>
<span data-nocopy="TEXT GOES HERE"></span>
<span data-nocopy="AND HERE"></span>
Demo: http://jsbin.com/fob/1/edit
This works in Firefox, Safari, and Chrome due to 21-year-old(!) bugs in selecting generated content:
But in old IE (< 8) the text will be completely invisible; in newer IE it should be visible but may well be copyable. In general don't use this technique for anything critical, as these bugs might get fixed one day...
And use sparingly, as this can be very user-hostile.
` have two columns that all scale according to their contents? I had a `
` layout originally, but it was impossible to justify the line numbers evenly in one column. I'm also trying to keep line wrapping enabled, which is why I think the table layout is the most appropriate.
– Blender Aug 20 '12 at 22:57- but it made sense as you use the css to generate the line nr's and then google doesn't have to index your numbers, just the code. (I didn't mean you should put the code in the
as you get the same problem, but I clicked too fast)
– Tessmore Aug 20 '12 at 22:59`; this has consistently been the best way I've found to create line numbers that aren't selectable.
– Phrogz Aug 20 '12 at 23:29` is line wrapping.
– Blender Aug 20 '12 at 23:31` because the left column's width had to be fixed. I doubt that I would ever put anything with more than 100 lines inside of one of these boxes, but I just don't see what the problem is with tables in this instance.
– Blender Aug 21 '12 at 20:52