Making a div be the width of the content inside it

I’ve been using CSS and HTML for a while now on and off, although I never really took any tutorials, prefering just to search for answers on the internet to any problems I’ve had and looking at others’ webdesigns and how they’ve been done.

I’m making a site currently in which there is a main containing div that automatically centers horizontally (all works fine, pretty basic stuff obviously) but I want it to automatically resize to the width of the content. I tried width: auto at a guess but it didn’t work.

Is this possible? (surely it must be?) and how?

Thanks, b3