I want to make the first line of a paragraph bold only when the user hovers over the first line of the paragraph. I tried something like:
p::first-line:hover {
font-weight: bold;
}
Please note that this question is different from another Stack Overflow question. The referenced question is about how to make the first-line of the paragraph bold when the user hovers over any part of the tag. My question is how to make the first-line bold when user hovers only over the first line.
2
Answers
How you have tried it is correct per the relevant CSS specification:
However, this specific feature combination is not yet implemented in any browsers (e.g. Firefox v123 and Chromium v123). In the future, browsers may support this, and this answer can be updated at that time. In the meantime, you’ll need to use JavaScript to achieve that functionality.
The only way I can think off as things stand with CSS at the moment is slightly hacky as it introducwa an otherwise spurious element into the DOM.
This snippet puts a span over the first line and it is hovering that that triggers style changes in the neighboring p element.