I need a cursor that I can move between two cells in a table. Here is the jsFiddle: http://jsfiddle.net/KNc5u/
If you click on the table, the cursor will cycle between selecting the whole cell, selecting the bottom of the cell and the top.
As you can see, the table “jumps” while the cursor moves because the border width changes. This is ugly. How can I prevent this?
Constraints:
- Cursor must be 2 pixel wide (not 1 and not 3)
- Pure CSS preferred
- No additional HTML elements, please (I could do this easily by wrapping each cell with a
divwith a 1 pixel white border that I turn black but I’m looking for a solution that doesn’t add junk to the DOM) - CSS3 is OK
- I can live with IE10+ 🙂
As you said you’re ok with css3 you can fiddle with box-shadow: http://jsfiddle.net/KNc5u/10/
This example works only with modern browsers and does not using any vendor prefixes like
-mozor-webkit. If you need support other browsers you can easily add these prefixes to the existing box-shadow properties.Feel free to change the color keywords to your needs…
Update
Here is a updated version (imho to hacky): http://jsfiddle.net/KNc5u/13/
However it should fixe your issues for the provided markup. Note that there is a hint: This example will only work in a proper way with similar colors for
tdand yourselected,selBottomandselTopclasses.Update 2
Now with left and right support: http://jsfiddle.net/KNc5u/15/