Here are the official docs on how to make your UI handle various resolutions and aspect ratios cleanly:
Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:
Usually you need to choose a suitable ScaleMode and MatchMode in the Canvas Scaler and stick with it 100%. Generally if you change those settings you will often need to redo your UI entirely.
Here’s some more fit-inside-UI-content notes:
I also use this CanvasScalerOrientationDriver utility to make sharing UI for Landscape / Portrait easier. Read what it does carefully.
Generally cameras are tied height-wise to the .orthographicSize, or the .fieldOfView
You can test directly in the UnityEditor Game window by choosing custom aspect ratios and pixel ratios, and you should do this for all anticipated major screen geometries, then test and fix your program until it works the way you want.
To tie it to the width, use ratios with the Screen.width and Screen.height, or alternately whatever pixel viewport you are rendering to. Remember those are integers so dividing them properly requires casting at least one of them to a float