Ristricting child translation to single axis
Use a child of constraint on B, set the Target to A and select only Location X.

A's location on the X axis will affect B, all other transformations will not.