2

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?

1
  • 2
    Separate css, with code only accessing style names, is a default approach in Vaadin. You can use CSSInject addon to apply styles through code. AFAIK, there is no inbuilt way to access component styling programmatically. Commented Jul 29, 2013 at 8:49

1 Answer 1

3

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.