How to only style the caption of a VerticalLayout?

I want to apply css styles to only the caption of a VerticalLayout. I do not want that child elements are affected.


TextField user = new TextField(“username”);
TextField pass = new TextField(“password”);
VerticalLayout fields = new VerticalLayout(user, pass);
fields.setCaption(“left aligned caption”);


Result: Both TextFields have a space on the left. The caption does NOT.

How can I set a padding only to the caption of the vertical layout?

I tried:


.padding .v-captiontext {
	padding: 20px;

BUT this will also add an extra padding to the captions of the contained TextFields.

So how can I only align the VerticalLayout caption?

I know this post is very old but is there a way to say just change the background color of the caption for a VerticalLayout?