3

I'm working on an application that will return some of its results as a massive HTML table. To keep the rows and columns from being resized by text hundreds of cells away, any cell content that's more than a certain length is hidden until clicked, by being wrapped in this HTML:

<label class="showlong">Show long text? <input type="checkbox" /></label>
<span class="hidden">{text}</span>

With corresponding CSS:

.hidden {
    display: block;
    height: 0;
    width: 0;
    overflow: hidden;
}
label.showlong:has(input:checked) ~ .hidden {
    display: inline;
}

Setting the height and width to 0 and hiding the overflow means that this content can still be found with ctrl-F, while not actually appearing until the user clicks the checkbox.

Overall, this works all right. But when the user searches for some text that's hidden, I'd like to highlight the cell in question, so that they know what exactly they should click.

The :focus-within selector seems ideal for this, but it doesn't recognize the "focus" placed on text during a search. Is there any way of detecting this other "focus" in CSS or JavaScript?

6
  • As you understand, this is not focus at all. For the highlighting related to the search in page, I don't know a simple solution. Some custom behavior and rendering can be implemented using CSS Custom Highlight API, but this is not pure CSS. Commented Feb 28 at 2:14
  • Related Commented Feb 28 at 2:44
  • Unfortunately, it wouldn't make a solution. I don't think this is what you wanted to achieve. Related, yes... Commented Feb 28 at 4:13
  • @SergeyAKryukov Oh, not a solution at all. Just linking it since it's a related question; CSS has advanced a lot since 2012, and things may be possible now that weren't before. Commented Feb 28 at 4:23
  • Yes, hopefully. Commented Feb 28 at 5:00

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.