membersound
membersound

Reputation: 86915

How to add CSS inline in Vaadin?

Is it possible to add inline CSS code programmatically?

Like, I have defined a CSS separator like this:

.hr{
    border-top: 1px solid black;
    padding-bottom: 10px;
}

Now I sometimes want to have it in a different color or a different size. Would I have to create further .hr-black, .hr-blue css styles and apply them separately by .addStyleName()? Or can I somehow set the color programmatically?

Upvotes: 2

Views: 2334

Answers (1)

Paolo Forgia
Paolo Forgia

Reputation: 6746

No, you can only change CSS at specific component using component.addStyleName(), but you can use it dynamically, like this:

if (condition)
   component.addStyleName("black");
else
   component.addStyleName("blue")

Upvotes: 3

Related Questions