The example for the page number uses \llap/\rlap to print something to the left/right without moving the current point.
\documentclass[twoside]{book}
\usepackage[
headheight=14pt,
]{geometry}
\usepackage{color}
\definecolor{bgpagenum}{gray}{.82}
\definecolor{fgheader}{gray}{.5}
\usepackage{fancyhdr}
\pagestyle{fancy}
\makeatletter
\let\ps@plain\ps@fancy
\makeatother
\fancyhead{}
\fancyfoot{}
\renewcommand*{\headrulewidth}{0pt}
\renewcommand*{\footrulewidth}{0pt}
\fancyhead[RO]{%
\textcolor{fgheader}{%
\rightmark
\rlap{%
\hspace{\marginparsep}%
\hspace{-\fboxsep}%
\colorbox{bgpagenum}{%
\makebox[\textwidth][l]{\thepage}%
}%
}%
}%
}
\fancyhead[LE]{%
\textcolor{fgheader}{%
\llap{%
\colorbox{bgpagenum}{%
\makebox[\textwidth][r]{\thepage}%
}%
\hspace{\marginparsep}%
\hspace{-\fboxsep}%
}%
\leftmark
}%
}
% sans serif font as main font
\renewcommand*{\familydefault}{\sfdefault}
\begin{document}
\chapter{Asdfg}
\section{Hjkl}
\newpage
\section{Yuip}
\end{document}
I have used \marginparsep as horizontal distance from the page number to the text body. Then the page number would be vertical aligned with marginal notes, if there are any.
If the page number should also be outside the marginal notes, then add \hspace{\marginparwidth}. The length the gray box can be calculated:
\dimexpr\paperwidth-\textwidth-1in-\oddsidemargin\relax % odd pages
\dimexpr\paperwidth-\textwidth-1in-\evensidemargin\relax % even pages
The example simplifies it by using a larger width (\textwidth).
The other things depend on used class/packages and, what have you already managed.