The metallicity and elemental abundance gradients of simulated galaxies and their environmental dependence