The job of the lens is to project an image of the outside world on the surface of film or digital sensor.
To do this job, light rays from the subject traverse the lens and the shape of the lens surfaces and the density of the lens alter their travel path. In other words, the lens acts a light wave guide. The focal length is a measure of the distance, lens to image plane. A 100mm lens forms an image of a far distant object 100mm downstream of the lens. However, the focal length is actually a variable depending on object distance. Nearby objects come to a focus further than 100mm d downstream.
Additionally, the color of the object also influences the lens-to-image distance. Blue comes to a focus closer to the lens while red focuses last, the other colors at in-between distances. We are talking, chromatic aberration. To correct, the optician constructs the lens using multiple glass elements, each with different power and density. This method brings the red and violet rays to a focus at nearly the same place. This color corrected lens is called an achromatic, Latin for without color error. We wish this were true but alas, some residual aberration remains.
If the lens is poorly constructed, the resulting image consists of a series of image, each a different color, juxtaposed, Because of projection distance of warmer colors is elongated, the yellow and red image are somewhat larger than the blue and violet images. What happens is, the final image is befringed with a halo or rainbow of colors. Object distance plays its part. The separation of the various images is more pronounced when the lens is working in close.
Addendum Yes subject distance impacts chromatic aberration.
To correct for chromatic aberration, two lenses are combined. The first is a converging lens made from crown glass. This lens produces images at different distances downstream from the lens. First violet comes to a focus, then the other colors based on their wavelength. Red and infrared come to focus further downstream. The second lens is a diverging lens made of flint glass. The behavior of the two are opposite as to color. This companion, called an achromatic Put together, this compound converging lens well corrected for color imaging. However, residual color errors has the effect of producing different sized images for each color.
This color error is sometimes called chromatic difference of magnification. The magnitude of this error is focal length dependent. As you image closer and closer to a subject, the back-focus distance elongated. Technically the focal length remains unchanged as you close focus. This is because focal length is defined as a measurement taken when the camera is imaging an object at infinity.