Hong Kong is literally right next door to China. It's within artillery range of Chinese territory. Any attempt to defend it against the largest army in the world would have been absolutely hopeless, and would probably have led to Hong Kong being levelled. Even if Britain had won, it would have been a pyrrhic victory. read more
A key difference with the Hong Kong cessions is that neither Spain nor Britain wish to fight a war over Gibraltar. From a realpolitik perspective, compared to Hong Kong, Gibraltar is far more defensible, and Spain considerably less formidable. read more