Is there a way to apply CSS like styles to a package and class hierarchy?

0 votes
asked Apr 13, 2024 in Question / help by jlo2k (160 points)
I would like to define some style attributes at the package level e.g. headerbackground, line thickness, show stereotype not on package but included classes. In the current documentation and some other sites i do not find any information how package and class can be adressed through hierachical styles.

1 Answer

0 votes
answered Mar 7, 2025 by dickmaley (4,160 points)

css styling can be applied to packages

image

@startuml
<style>
root {
  --default-BackGroundColor: White Smoke;
  --default-DiagonalCorner: 0;
  --default-FontName: SansSerif;
  --default-FontSize: 14;
  --default-FontSize-Title: 24;
  --default-LineThickness: 2.0;
  --default-note-BackgroundColor: #white/LemonChiffon;
  --default-RoundCorner: 25;
  --default-Shadowing:3.0;
  BackGroundColor: var(--default-BackGroundColor);
  DiagonalCorner: var(--default-DiagonalCorner);
  FontColor: black;
  FontName: var(--default-FontName);
  FontSize: var(--default-FontSize);
  FontStyle: plain;
  HorizontalAlignment: left;
  HyperLinkColor: blue;
  HyperLinkUnderlineThickness: 1;
  LineColor: black;
  LineThickness: var(--default-LineThickness);
  RoundCorner: var(--default-RoundCorner);
  Shadowing: 0.0;
  }
  
  arrow {
    FontColor: black;
    FontName: Sans Serif;
    FontSize: 12;
    FontStyle: Bold;
    LineColor: black;
    LineThickness: 3;
  }
  actor {
    BackgroundColor:transparent;
    FontColor: red;
    FontSize: 12;
    FontStyle: Bold;
    LineColor: red;
    LineThickness: 3;
    RoundCorner:0;
    'RoundCorner: var(--default-RoundCorner);
    'Shadowing: 3.0;  
    Shadowing: 3.0;
  }
  package {
    BackgroundColor: #white/Aqua;
    FontColor: Blue;
    FontSize: var(--default-FontSize);
    FontStyle: Bold;
    LineColor: Blue;
    LineThickness: var(--default-LineThickness);
    RoundCorner: var(--default-RoundCorner);
    'Shadowing: 3.0;  
    Shadowing: var(--default-Shadowing);
  }    
document {
   BackgroundColor: transparent;
}
</style>
left to right direction
actor Guest as g
package Professional {
actor Chef as c
actor "Food Critic" as fc
}
package Restaurant {
usecase "Eat Food" as UC1
usecase "Pay for Food" as UC2
usecase "Drink" as UC3
usecase "Review" as UC4
}
fc --> UC4
g --> UC1
g --> UC2
g --> UC3
@enduml

...