Forum How do I...?

Prevent page break between element and text nodes

_savage
Hello,

Suppose I have (simplified) markup like so
<p>Lorem ipsum dolor sit amet, … <a id="label"/>Morbi in laoreet augue, ac placerat sem.</p>

There is no space between the <a> element and the “Morbi...” text node. If a page break was to occur right before “Morbi...” where would the <a> element be — on the previous page, or the new page?

This matters if <a> is the target of a cross reference where I’d expect the new “Morbi…” page to show.

Should I insert a word joiner after the <a> just to be sure?

Thank you!
Jens
mikeday
It might be more reliable to link to a span that wraps the text you want to link to, if that's possible?
_savage
I think I could wrap the index term into the <a> element
<p>Lorem ipsum dolor sit amet, … <a id="label">Morbi</a> in laoreet augue, ac placerat sem.</p>

if that pretty much guarantees that the page number aligns with the word?
mikeday
That should be reliable yes, it also avoids issues with links to empty inline elements that can affect anchors, although that is only if they occur in a block context if I recall correctly.