Stainers operate based on the chemical affinity of dyes to different cellular components. For instance, hematoxylin binds to acidic structures like nucleic acids, staining them blue, while eosin binds to basic components like proteins, staining them pink. This differential binding provides the necessary contrast for microscopic examination.