The trick is that you space out the intervals on which $g$ is closed to a fixed polynomial $P_n$, then you can just make $g$ linearly interpolate from endpoint to endpoint.
For instance, lets say that you have some sequence of polynomials $\\{P_n\\}_{n\in\mathbb Z}$ that is dense in $\mathcal C([0,1])$. Then, you can define, where $n\in\mathbb Z$ and $t\in [0,1]$: $$g(n+t)=\begin{cases}P_{n/2}(t)&\text{if }n\text{ is even}\\\ (1-t)P_{(n-1)/2}(1)+tP_{(n+1)/2}(0)&\text{if }n\text{ is odd}. \end{cases}$$ On the interval $[2n,2n+1]$, this $g$ is exactly a translate of $P_n$. On $[2n+1,2n+2]$, this $g$ just traces a line from one polynomial to the next. You can verify that this is indeed continuous and satisfies your property.