There really isn't a singularly based answer to this question, in that, the Spanish Empire's decline was due to a number of different factors, depending on a particular region of the world.
In the case of North America-(more specifically, the United States), Spain had colonized and controlled much of the continental United States from the 1500's, until the early 1800's. The Mexican Revolution and the eventual establishment of the Mexican Republic, was a major defeat for imperial Spain in the Western United States-(more specifically, Texas, the Southwest, Nevada and California). Florida, which had been a Spanish colony for centuries, had lost its power to the British and then eventually to a burgeoning American Republic by around 1820. And even though we know the old story of President Thomas Jefferson, the Louisiana Purchase and Napoleon Bonaparte, it was actually the Spanish Empire who directly preceded the French imperial presence in the Mississippi and wider Mississippi River region. Overall, in just the United States alone, whether it was imperial France, the British Empire, Mexico or a young American Republic, imperial Spain's colonial territories throughout much of the continental United States, were conquered and dismantled by more powerful Republics and Empires.
In the case of Gibraltar, the Moors had occupied this small, but strategically significant part of the world during the heyday of Islamic Spain. The Spanish Empire did conquer-(or really, "reconquered") Gibraltar and held it throughout much of the Modern era. But, with the growing British naval presence in the Mediterranean region, Gibraltar became Anglicized and continues to remain part of the United Kingdom to this day....nearly 300 years later.
However, there are two cities in neighboring North Africa which have existed under the Spanish state since the 1700's and have remained nearly uninterrupted-(that is to say they have never been conquered)...the cities of Ceuta and Melilla-(which are often nicknamed, the cities of "Spanish Morocco" or Spanish North Africa). So while the Spanish Empire lost strategically significant Gibraltar to the British, they did conquer a small, but strategically valuable part of the Maghrebi coast-(much to the dismay of Morocco, as well as greater North Africa).
If you are an Arab or Berber Muslim living in either of these Spanish North African cities, you would most likely view the Spanish political presence as a continuously imperial presence, similar to the various "overseas territories" that are still "held" by the United Kingdom, the Netherlands and France. Spain, is also, a part of the post-colonial club of West European nations which still maintains its own..."overseas territories", such as the above mentioned cities in North Africa.
(And if you live in Catalonia and especially, the Basque country in the North of Spain, you may also have similar views regarding a continuous Spanish imperial presence, While Catalonia and the Basque country are part of the Spanish state, both of these Northern Spanish regions are culturally, linguistically and perhaps even genealogically distinct from the remainder of Spain).