CSS properties
Every KVision component has a full range of properties based on CSS specification. Most of them are 100% type-safe - based on enumeration values, dedicated classes and functions. You can of course use custom CSS stylesheets and assign predefined classes to your components (as explained in the Theming chapter), but KVision gives you a choice. With CSS properties you can style any component's size, position, margins, paddings, borders, colors, backgrounds, text and fonts with pure Kotlin code.
Most of the CSS properties are defined in the pl.treksoft.kvision.core.StyledComponent class.
An example of setting CSS properties for a DIV element.
CSS units
KVision supports all CSS units as an extension properties on Number
type. So you can specify dimensions, sizes, position and thickness with such example notations: 50.px
, 12.pt
, 2.em
, 90.perc
, 100.vh
, 1.49.em
etc.
Colors
There are two ways to specify colors. You can use hexadecimal Int
literals or predefined color names as the parameters of Color
class. To specify the "color" property, you can also use convenient setters: colorHex
and colorName
.
CSS helper classes
To specify borders, backgrounds, text decorations and text shadows you use the dedicated classes.
Style objects
When the CSS properties are set directly on the component, the corresponding style attributes are inlined in the generated HTML code. Sometimes it's better to define a CSS class, which can be reused by other components. In KVision you can do this using the Style
class. By instantiating the Style
object you create a CSS class definition. This definition can be assigned to any component with the addCssClass
method.
By default the class name is generated by KVision, but you can use your own with the Style
class constructor parameter.
Style objects can be nested to create CSS subclasses.
Last updated