The British were very avid buyers of China's silk and tea. Because of this, they were losing silver to China. This was running down the British supply of silver.
Because of this, they really wanted to find something to sell to China to recoup some of the loss of silver. They hit on opium, which came from British India.
However, the Chinese banned the opium trade. This caused Britain to fight China in the Opium Wars. So, the wars happened because Britain needed to sell opium to China to get back some of the silver they lost to China by buying tea and silk.
At the beginning of nineteenth century China exported large quantities of tea and silk to the Western countries. However the western countries did not have much to export to China to pay for the imports. To correct this imbalance in trade the European trades began to Export to China the Opium grown in India. However because of ill effect of opium on its people, China banned its import. However the Europeans traders continued to smuggle opium in to China.
To stop this illegal trade in opium, in 1839 the Chinese tried to seize 20,000 chests of opium from British merchants from Guanzhou. The British responded by attacking the Chinese to force them to let trading in opium continue unrestricted. THis resulted in breaking out of war, called opium war, between the Britain and China. The war was easily won be the British and China was forced to sign the treaty of Nanjing in 1842.