Search code examples
cssword-wraphtml-heading

Append text to H1 tag that has wrapped onto 2 lines


I have an H1 tag and on the same line, immediately following the H1 tag I have a link (inside a SPAN). I have both the H1 tag and the SPAN tag set to float:left and they appear on the same line, which as how I want it.

However, in the occasional sccenario when the H1 tag has so much text it wraps onto a 2nd line, the following SPAN tag (with link inside) no longer sits neatly behind the last part of the H1 tag, but instead appears on the next line down.

<h1 style="float:left;">some really long text here ... blah</h1><span style="float:left;"><a href="">my link</a></span>

This currently renders like this...

some really long text here ...
blah
my link

..but I'd really like it to appear like this...

some really long text here ...
blah my link

How can I force it to always keep the SPAN (containing my link) directly behind the last word of the H1 tag, WITHOUT resorting to putting my link/span inside the H1 tag block?


Solution

  • Change h1 to display:inline, there's no need for float:left then either.