I want to achieve something similar to this, but the X would not be aligned with js and I don't think there's a way to calculate the text's position to center the X.
I tried also ::selection::after { content: '☓'; }
, this is not working either.
Here is my code example. I attached the event on the right click, on opening context menu.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
Lorem ipsum dolor sit amet consectetur adipisicing elit.
</div>
<div class="X" style="background-color: red; width: 12px;">☓</div>
<script type="text/javascript">
document.oncontextmenu = function(e) {
const xElement = document.querySelector('.X');
const styleValue = 'position: fixed; background-color: red; width: 12px; ' + 'top: ' + e.y +'px; ' + 'left: ' + e.x +'px;';
xElement.setAttribute("style", styleValue);
}
</script>
</body>
</html>