The war came about through a trading inefficiency. The Chinese markets at the time (still holds relatively true today) was a selling market, not a buying market. They weren't interested in European goods. So European trading vessels would have to stock up on silver as currency, and sail to China to trade the silver for desirable goods such as porcelain and silks.
European merchants didn't like this because its far more efficient to profit on every leg and the first leg of hauling silver was a loss with a mostly empty hold, so were seeking a product to sell to the Chinese market that would have pull that they could fill cargo holds with. Due to their lack of scruples, they discovered that opium was such a product and set in motion the very events that still plague us to today of growing opium across Asia to sell to China.
As a flood of cheap opium entered the market through the criminal gangs at the time (who were buying the opium through profitable liaisons with the British) the Chinese authorities set about cracking down on the trade in the interests of its people. Eventually this brought them into conflict with the British and in interests of keeping the ports open to the opium trade the first of two opium wars was declared.
The wikipedia article probably puts it better than I have [1].
> They created this difficulty to find a chance to invade.
If they were seeking to invade then European possessions in China would have been significantly greater than Hong Kong given the weakness of the Qing dynasty over the course of the 19th century (although it would have still been a significant challenge given the might of China's manpower at the time). The British were a brutal force but in a similar fashion to today's US hegemony they were not always primarily motivated by conquest and annexation, wealth was more of a primary motivator. So its much like US foreign policy today which is typically flexed to promote interests relevant to American GDP. It remains ugly when its flexed but its arguably a kinder aim than that of a fully imperialistic force such as say: the Mongols of the 14th and 15th centuries.
[1] https://en.wikipedia.org/wiki/Opium_Wars