Hello,
This is something that I have struggled with for a long while without finding a proper solution.
Lets say I have a horizontal layout group that has a couple of buttons in it. I want each button in the horizontal layout group to fit the text within the button.
The buttons have an image as background and a text as a child.
Imagine the following layout of gameobjects and components:
--Content
[Horizontal Layout Group]
----Button 1
[Image]
[Button]
------Button Text
[Text Mesh Pro Text]
----Button 2
[Image]
[Button]
------Button Text
[Text Mesh Pro Text]
This is what I want it to look like:

The blue rectangle here is the content GameObject with the horizontal layout group.
I can add a content size fitter to the Text component in the button but this will not make the button’s background scale accordingly. I can tell the horizontal layout group to expand the children but it will not respect the text’s width. Adding a content size fitter to the button is not allowed because the horizontal layout group is the parent.
Can anyone help me out on this one? I have seen many different discussions on different forum posts but none seem to solve my issue.
Thank you in advance.
