Apply a Content Size Fitter and a Horizontal Layout Group to the parent panel, and set the Content Size Fitter component's settings both to "Preferred Size". This makes it resize (with optional padding) to fit the preferred size of whatever its contents are. You can use Layout Element nodes on the contents as well to influence that target size, but usually you don't want to.
↧