The problem is how to make the panel same size as the Text.
If panel is a child gameobject of Text, then panel can be same size as Text, but Text is convered by the Panel.
If the panel is parent of the Text,or sibling of the Text, then I tried all kinds of IXXXLayout interface, it can’t resize the panel to the Text size.
You can achieve this by using a LayoutGroup on your background Image as the parent, and a LayoutElement on your Text as its child. The LayoutElement will expand to its minimum size, and the LayoutGroup will expand to fit its child.