You can set the header in a \colorbox
in the centre only, and then spread the contents to the left/right/centre as needed.

\documentclass{article}
\usepackage{fancyhdr,xcolor}
\usepackage{lastpage,lipsum}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{%
\setlength{\fboxsep}{0pt}% Remove \fbox gap
\colorbox{blue!15!white}{%
\makebox[\textwidth]{%
\rlap{\textsl{Title}}% Left header
\hfill
\clap{}% Center header
\hfill
\llap{\textsl{Page \thepage\ of \pageref{LastPage}}}% Right header
}% \makebox
}% \colorbox
}% \fancyhead
\renewcommand{\headrulewidth}{0pt}
\begin{document}
\sloppy\lipsum[1-50]
\end{document}
All elements are placed with zero width (via \rlap
for the left header, \clap
for the centre and \llap
for the right header) so as to not affect its placement relative to their width.
tikz
more intuitive as given here -- tex.stackexchange.com/questions/527916/…