Currently there is lots of Javascript around that handles tooltips/popovers, for example popper (https://popper.js.org/).
A lot of what those libraries do is compute placement based on a position of an element relative to the current viewport.
The idea is to avoid those computations in JS, by having a pseudo-element that gets triggered by the position of an element relative to the viewport.
For example:
a:viewport-position(top below 50%) .popup {
bottom: 100%;
}
This would allow creating pretty complex popover positioning without Javascript at all.