The American civil war presented a welcome breathing space for Spain, and an opportunity to either to intervene directly or to expand their presence in the Americas. They shied away from recognising the Confederacy, not least because Southern politicians had been those most vocal in calling for annexation of Cuba, but a 2nd Reconquista, that was possible.
All this was going to take strength, and allies. The Spanish fleet was built up and modernised until it was judged the 4th most powerful in the world, with modern ships, including the Numancia, an ironclad frigate and not only one of the most powerful ships afloat but also blessed with a huge range. She would go on to be the first ironclad to circumnavigate the globe. There were also several modern steam powered frigates, making a relatively small but potent fleet. Significantly, these were long range, blue water, forces, not designed just for coastal defence. Spain at this time also still held Cuba, the Philippines and Puetro Rico, despite numerous revolts, providing island bases.
The first opportunity to assert herself was Mexico. Following victory in a civil war, largely with United States aid, the new government of Benito Juarez suspended debt interest payments to Britain, France and Spain, the major creditors. Intense negations took place between the French, Spanish, British and the United States, who were also invited to take part. The US declined, but nonetheless, the other three powers, for their own very different reasons, signed the Treaty of London agreeing to impose a solution by blockading the Mexican coast and occupying the main port of Vera Cruz.
The Spanish government had been angry at Mexico for some time, not just for debt default, but also for attacks on Spanish citizens in Mexico, and for ideological reasons, the Spanish Court identifying much more with the opponents of Juarez. There had even been suggestions of a declaration of war but these were defused, in part by General Prim, one of the victors in Morocco who was actually married to a niece of Juarez's treasurer!