Recognising a screen size change

This is called responsive design and has nothing to do with WordPress, it is an extension rule to media queries (@media) in CSS3. CSS is a browser/client side language which can determine window sizes and browser types, this is what is used to determine how a website should look at a specific window size or browser. This media queries, when specified in CSS, will be used to resize a specific item to the required set size accordingly

Some themes also incorporate javascript together with CSS to display HTML selectors differently on different window sizes and browser types.

I’m not going to go into more details as this really is not WordPress specific, you should take your time to read up on responsive design and media queries