Utilities
Height
The Height
utility is used to assign fixed heights to UI elements.
Utility Class | USS Properties |
---|---|
h-0 | height: 0px; |
h-1 | height: 4px; |
h-2 | height: 8px; |
h-3 | height: 12px; |
h-4 | height: 16px; |
h-5 | height: 20px; |
h-6 | height: 24px; |
h-7 | height: 28px; |
h-8 | height: 32px; |
h-9 | height: 36px; |
h-10 | height: 40px; |
h-11 | height: 44px; |
h-12 | height: 48px; |
h-14 | height: 56px; |
h-16 | height: 64px; |
h-20 | height: 80px; |
h-24 | height: 96px; |
h-28 | height: 112px; |
h-32 | height: 128px; |
h-36 | height: 144px; |
h-40 | height: 160px; |
h-44 | height: 176px; |
h-48 | height: 192px; |
h-52 | height: 208px; |
h-56 | height: 224px; |
h-60 | height: 240px; |
h-64 | height: 256px; |
h-72 | height: 288px; |
h-80 | height: 320px; |
h-96 | height: 384px; |
h-px | height: 1px; |
h-0point5 | height: 2px; |
h-1point5 | height: 6px; |
h-2point5 | height: 10px; |
h-3point5 | height: 14px; |
h-1of2 | height: 50%; |
h-1of3 | height: 33.333333%; |
h-2of3 | height: 66.666667%; |
h-1of4 | height: 25%; |
h-2of4 | height: 50%; |
h-3of4 | height: 75%; |
h-1of5 | height: 20%; |
h-2of5 | height: 40%; |
h-3of5 | height: 60%; |
h-4of5 | height: 80%; |
h-1of6 | height: 16.666667%; |
h-2of6 | height: 33.333333%; |
h-3of6 | height: 50%; |
h-4of6 | height: 66.666667%; |
h-5of6 | height: 83.333333%; |
h-1of12 | height: 8.333333%; |
h-2of12 | height: 16.666667%; |
h-3of12 | height: 25%; |
h-4of12 | height: 33.333333%; |
h-5of12 | height: 41.666667%; |
h-6of12 | height: 50%; |
h-7of12 | height: 58.333333%; |
h-8of12 | height: 66.666667%; |
h-9of12 | height: 75%; |
h-10of12 | height: 83.333333%; |
h-11of12 | height: 91.666667%; |
h-full | height: 100%; |
Usage Example in UXML
Fixed Size Height
Classes like h-4 set a fixed height for an element. For instance, h-4 sets the height to 16px.
<ui:VisualElement class="h-4">
<!-- Element with a fixed height of 16px -->
</ui:VisualElement>
Proportional Height
Classes like h-1of2 set a proportional height for an element. For instance, h-1of2 sets the height to 50% of the parent container.
<ui:VisualElement class="h-1of2">
<!-- Element with a height of 50% of the parent container -->
</ui:VisualElement>
Full Height
The h-full
class sets the height of an element to 100% of the parent container.
<ui:VisualElement class="h-full">
<!-- Element with a height of 100% of the parent container -->
</ui:VisualElement>
Customize
Modifier Variations
You can customize which modifier variations of the Height
utility are generated, such as pseudo-classes (e.g., hover
, focus
) and custom modifiers.
Height
utility.By fine-tuning the utility variations, you maintain control over your stylesheet's size and complexity, ensuring that only necessary styles are included. To update these values:
- Open the Theme Config Asset: Find the asset within your Unity project.
- Navigate to the 'Utilities' Section: Locate the
Height
utility. - Adjust Modifier Variations: Select which modifiers you want to be generated for the utility. Keep in mind that the order of the modifiers will affect the order and specificity of the generated USS classes.
Class Tags and Properties
The Height
utility generates classes based on predefined tags and their associated USS properties. While we recommend keeping these defaults for consistency and ease of reference in our documentation, you have the option to customize them to suit your project's specific needs.
These values are prepended to the defined values in this format tag-{value}
. If a tag is empty, the generated class will simply be the value by itself.
Here are the default tags and the USS properties they set for the Height
utility:
- h : height
To customize these tags and properties, you can edit the Tag Property Map
field for the Height
utility in the Theme Config asset. This allows you to define new tags or modify existing ones, thus tailoring the generated classes to your preferences.
Extending Core Fields
The Height
utility uses values from the following fields from the Core
section of the Theme Config asset:
- Spacing
To customize or define these extended fields:
- Open the Theme Config Asset: Locate the asset within your Unity project.
- Navigate to the 'Utilities' Section: Find the
Height
utility. - Customize Extend Fields: Modify or add fields in the
Extend Fields
array to change the core configuration values that are extended. You'll only be able to extend fields of the same type.
Disable Utility
The Height
utility is enabled by default. You can disable it by unchecking the Enabled
option in the Theme Config asset. This will prevent the generation of the utility's styles.