In the years before 1914, Italy seems to have viewed Germany and Austria-Hungary as a matched set. Thus, the closer Italy moved towards Germany, the closer it moved to Austria-Hungary as well.
An important factor in this dynamic was the bifurcated nature of Italian irredentism. Italian nationalists believed that substantial territories that were then part of France and Austria-Hungary ought to be part of the Kingdom of Italy. This made both France and Austria-Hungary the "natural enemies" of Italy.
However, with Austria-Hungary so closely tied to Germany, and France and Germany the two powers in Europe with the greatest antipathy towards each other, any move against one of the "natural enemies" strengthened the position of the other.