Imagine you have a div in an html document with absolute positioning, like this:
<div style="position:absolute">Hello!</div>
Now, if you want to set a specific X and Y position for the div (potentially using JQuery), it's pretty straightforward - just assign values to the "left" and "top" properties. However, things get trickier when you want to position the div at its center. This becomes challenging when the size of the div is not fixed, as you can't simply offset the X and Y coordinates accordingly.
Is there a way to set the center of a div at a specific X and Y position? It's worth mentioning that these divs will only contain text, without any child elements.
While I'd prefer a solution using CSS over JavaScript, I am open to using JavaScript if necessary.