Showing posts with label css. Show all posts
Showing posts with label css. Show all posts

Thursday, April 6, 2023

Web Design: Copy To Clipboard with an SVG Graphic!

 Been a long time since I've had time to post. Now, let's get into the meat of this. It's easy enough to copy to a clipboard in Javascript. I did that. Let's also talk using a graphical icon to make it not look like garbage. The Javascript code to copy to a clipboard looks something simple like this:


navigator.clipboard.writeText(document.getElementById("elementwithvalue").value);


Easy enough. Now, let's talk a dead simple icon that takes up little to no room and is easy enough to copy and alter.


<svg width="20px" height="20px">

<rect x="3" y="3" height="12px" width="12px" rx="3" ry="3" style="stroke-width:1;stroke:black;fill:white"/>

<rect x="7" y="7" height="12px" width="12px" rx="3" ry="3" style="stroke-width:1;stroke:black;fill:white"/>

</svg>


Easy enough, just a little black and white icon that looks close enough to the double paper thing to do a thing. All together it might look something like this:


<input type="text" id="kopimi">Something useful</input><button type="button" onclick="navigator.clipboard.writeText(document.getElementById('kopimi').value)" style="padding0;margin0"><svg width="20px" height="20px">

<rect x="3" y="3" height="12px" width="12px" rx="3" ry="3" style="stroke-width:1;stroke:black;fill:white"/>

<rect x="7" y="7" height="12px" width="12px" rx="3" ry="3" style="stroke-width:1;stroke:black;fill:white"/>

</svg></button>


And there you have it, a stupid little input box with a copy icon button. Enjoy, copy whatever.

Tuesday, April 3, 2012

CSS3 ::selection

While working on some stuff I cam across a CSS3 pseudo-class selector called ::selection. While this is something you can do in javascript, it makes things a lot easier when styling can all be done in CSS rather than javascript workarounds. The javascript equivalent would be rather annoying to do. So the CSS3 way, as with any CSS, is rather simple and quick to do, minus a few catches here and there. CSS3 still lacks a good deal of support and isn't good if you want some real backwards compatibility, however I'm more interested in how to use this to just screw with things in ways it could be exploited, bad or just annoying and this particular property hit right on the head for some annoying fun.

You may wonder how this could be annoying, and quite simply, think about what would happen if selected text disappears. It would no longer be selected and then have to reappear, unselected. Thus the end result is text you cannot highlight without altering the CSS. So the code for that looks something like this.
::selection {
  display: none;
}
::-moz-selection {
  display: none;
}

I've only tried this in Firefox 10, but when I do it on Firefox, the text is impossible to highlight, however I can drag the text. As to the effects it will have in other browsers that support it, well that's all part in the fun in trying to mess with things to get results like this.

Try to highlight this and see what happens if your browser supports it.