When learning about closed range theorem, I met a problem as follows: suppose $X$ is a Banach space and $E$ is a closed subspace of $X$. Denote $$ E^{\perp}=\{g\in X^*\ |\ g(x)=0,\quad\forall x\in E\}. $$ Then for any $f\in X^*$, it claims that $$ \operatorname{dist}(f,E^{\perp})=\sup_{x\in E\atop \|x\|\leq1}f(x). $$ It is clear for me that the right is not less than the left since for any $x\in E$ and $g\in E^{\perp}$: $$ f(x)=(f-g)(x)\leq\|f-g\|\|x\|. $$ Take $\sup$ w.r.t. $x$ and take $\inf$ w.r.t. $g$, it turns out that $$ \operatorname{dist}(f,E^{\perp})\geq\sup_{x\in E\atop \|x\|\leq1}f(x). $$
If $X$ is reflexive, then by Hahn-Banach theorem we know there exists a $G\in X^{**}$ s.t. $$ G(f)=\operatorname{dist}(f,E^{\perp}),\quad G\big|_{E^{\perp}}=0. $$ and there is a $x\in X$ s.t. $G=x^{**}$, i.e. $G(f)=f(x)$ holds for any $f\in X^*$. Then for any $g\in E^{\perp}$ we can get $$ g(x)=G(g)=0, $$ which means that $x\in E$ and the conclusion holds.
But for general case I have no idea. Any advice will be helpful!
The Hahn-Banach theorem is valid for general topological vector spaces (not just with the topology induced by the norm).
Look at "Geometric Hahn-Banach" here [1]. In the real case, if $(Y,\tau)$ is a locally convex topological vector space, $A,B\subset Y$ are non-empty and convex, if $A$ is $\tau$-compact, and $B$ is $\tau$-closed, then there exist a $\tau$-continuous linear functional $\Lambda:Y\to \mathbb{R}$ and $s,t\in \mathbb{R}$ with $s<t$ such that for all $a\in A$ and $b\in B$, $$\Lambda(a)<s<t<\Lambda(b).$$
Apply this with $Y=X^*$ and $\tau$ the weak$^*$ topology. Fix $0<\varepsilon<\text{dist}(f,E^\perp)$ and let $B=G^\perp$, $$A=\{g\in X^*:\|f-g\|\leqslant \varepsilon\}.$$ $B$ is weak$^*$-closed and $A$ is weak$^*$-compact. Apply the theorem to get some weak$^*$-continuous linear functional as above, and note that a weak$^*$-continuous linear functional on $X^*$ has the form $h\mapsto h(x)$ for some $x\in X$.
It must be the case that $x\in E$. If it were not so, by the usual Hahn-Banach, there would exist some $g\in E^\perp$ such that $g(x)>0$. Since $\lambda g\in E^\perp$ for all scalars $\lambda$, $$f(x)<\inf_{y\in E^\perp} y(x)\leqslant \inf_\lambda \lambda g(x)=-\infty.$$ So $h(x)=0$ for all $h\in B$. We know $$f(x/\|x\|)+\varepsilon\leqslant \sup_{a\in A}a(x/\|x\|)\leqslant \inf_{b\in B}b(x/\|x\|)=0.$$ So $f(x/\|x\|)\leqslant -\varepsilon$, and we can consider the action of $f$ on $-x/\|x\|$.
[1] https://en.wikipedia.org/wiki/Hahn%E2%80%93Banach_theorem#Hahn.E2.80.93Banach_separation_theorem
ACCEPTED]
Apply Hahn-Banach to $E\subseteq X$ instead of $X^*$: Let $g$ be an extension of $f\rvert_E$ to $X$ with $\lVert g\rVert= \lVert f\rvert_E\rVert$. Then $f-g\in E^\perp$ and so $\operatorname{dist}(f, E^\perp)\leq \lVert f+(g-f)\rVert=\lVert g\rVert=\lVert f\rvert_{E}\rVert=\sup_{x\in E, \lVert x\rVert =1}|f(x)|$.
Or another (actually the same but spelled out differently) way: The restriction map $X^*\to E^*$ maps the open unit ball of $X^*$ onto the open unit ball of $E^*$ (Hahn-Banach) and its kernel is $E^\perp$, so we get a bijective map $X^*/E^\perp\to E^*$ which maps the open unit ball onto the open unit ball and is therefore an isometry. But the norm on the quotient space is precisely given by $\lVert f+E^\perp\rVert = d(f,E^\perp)$ and the norm of the restriction $f\rvert_E\in E^*$ is the other side $\sup_{x\in E, \lVert x\rVert =1}|f(x)|$.