Search code examples
javacssfont-sizevaadin7caption

How to make the font-size of the caption of a Vaadin Label smaller?


I know how to add styles in Vaadin and I've done multiple stylings in my css and added the style in the code succesfully, but this one eludes me.

I tried the following:

in the css I have the following style:

  .v-caption-mystyle .v-captiontext {
    font-size: 13px !important;
    font-weight: bold;
    color: $dark-grey;
  }

In the code I try to set it in two following ways and nothing happens:

postalCodeLabel= new Label(currentAddress.getPostalCode());
postalCodeLabel.setCaption("Postal code"));
postalCodeLabel.addStyleName("v-caption-mystyle");

postOfficeLabel = new Label(currentAddress.getPostOffice());
postOfficeLabel.addStyleName("v-caption-mystyle");
postOfficeLabel.setCaption("Post office"));

EDIT: Vikrant Thakur's answer works. In my case also this worked:

  .v-caption-invoiceaddress-label-caption .v-captiontext {
    font-size: 13px !important;
    font-weight: bold;
    color: $dark-grey;
  }

And in the Java:

postalCodeLabel = new Label(currentAddress.getPostalCode());
postalCodeLabel.setCaption("myCaption"));
postalCodeLabel.addStyleName("invoiceaddress-label-caption");

Solution

  • enter image description here

    Here is the code for theme scss file:

    @import "../valo/valo.scss";
    
    @mixin mytheme {
    
        // Insert your own theme rules here
        .v-caption-mystyle {
            .v-captiontext {
                font-size: 13px;
                font-weight: bold;
                color: red;
            }
        }
    
        @include valo;
    }
    

    And, here is the Java code:

    Label label = new Label("This is the label text");
    label.setCaption("This is the label caption");
    label.addStyleName("mystyle");