3

I have code formatted in pre. I use overflow: auto in case it gets too wide. Now I want to add documentation tooltips to whereever I use one of my extensions. All my extensions are bold.

There are extremely many examples, that use some of the same extensions over and over again. So my plan is to define the formatting once and add a class for each docstring:

<style>
pre { background: lightblue; width: 90vw; padding: 5px; overflow: auto }
pre b { position: relative }
b[class]:hover::after {
    position: absolute; z-index: 4; top: 100%; left: 0; min-width: 40vw;
    white-space: pre-line; font-size: .7rem; font-weight: initial;
    background: white; padding: 2px; border: solid 1px lightgray
}
.echo:hover::after {
    content: "Echo (E) or echo (e)\A Echo prettified args or $_ with spaces, for lowercase echo, with final newline.  In scalar or list context return prettified result instead.";
}
</style>
<pre>
these are 2 very long preformatted lines with the word <b class="echo">echo</b> that go on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on almost forever
these are 2 very long preformatted lines with the word <b class="echo">echo</b> that go on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on almost forever
</pre>

But both in FF & Chrome, even if I have only overflow-x, the box gets visually clipped in y-direction. One can use the mouse-wheel to scroll it into view, but that sucks big time! How can I let only my tooltip escape (as it would be with no overflow, but I need that)? I have tried various combinations of position, but this one seems the only one that puts the tooltip at the right position.

CSS overflow: auto hiding tooltip suggests position: fixed but then the tooltip doesn't appear at all.

So you can see what I'm talking about, in https://perl1liner.sourceforge.io/Collatz/ I have armed bold words in the blue code boxes with tooltip classes. Till this is solved, I do not have position: relative on these b-tags as I would want. Therefore the tooltip pops up under the whole code-box. :-( This page – including veggie-burger and its buttons – is proudly made without JavaScript (except the Math/Collatz linked subpage, coz Chrome still can't handle MathML). So I'm looking for a pure css solution!

2
  • In the code provided this works: pre:hover { overflow-y: visible; overflow-x: initial; } But there isn't enough info to know what the effect on long lines would be. Please could you cut the example code right down to show just one instance of the situaton and put that code as a working snippet into your question, not as a link. See stackoverflow.com/help/minimal-reproducible-example Commented Jan 14, 2022 at 7:49
  • @AHaworth Have made a full example. Your code works because you temporarily disable the scrollbar. Alas that breaks the layout, because now long lines jut out of the pre, and even out of the page, which then gets an x-scrollbar. Besides scrolling the pre sideways then becomes very fidgetty – you have to enter the scrollbar very carefully from the bottom. And that probably depends on OS and browser. Commented Jan 14, 2022 at 17:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.