Want to make sure I'm not hallucinating. Rings and algebras are commutative and unitary. Let $k$ be a ring and $A$ a $k$-algebra. Let $f\in A$, and identify $f\in A$ with the arrow $k[x]\to A$ which maps $x\in k[x]$ to $f$. Then the square below is a pushout in the category of $k$-algebras.
$$\require{AMScd} \begin{CD} k[x] @>>> k[x,x^{-1}] \\ @V{f}VV @VVV\\ A @>>> A_f \end{CD}$$
Is this correct?
Along this line, by pushout pasting and then dualizing, basic affines are pullback stable. Is this also correct?
That's exactly right. There's (at least) 2 ways to show this.
Show that any morphism of rings factors uniquely as a localization followed by a conservative morphism (a morphism $R\xrightarrow{f}R'$ is conservative if $f(r)$ invertible implies $r$ is invertible). This would imply that you have an orthogonal factorization system whose left class is the class of localizations and right class is the class of conservative morphisms. Since left classes of factorization systems are stable under pushouts, the claim follows.
Show that the pushout of the quotient $R\to R/f$ with $R\to S$ is zero if and only if $R\to S$ factors through the localization $R\to R_f$. In the language of affine schemes this means that principal open embeddings are complements to hypersurfaces. Since pullbacks of hypersurfaces are hypersurfaces (i.e. pushouts of quotients by a single element are quotient by a single element), it then suffices to check that, in any category, if a morphism has a complement and a pullback, the pullback of the complement and the complement of the pullback satisfy the same universal property.