Utilities
Max-Width
The Max-Width
utility is used to control the maximum width of an element. This is particularly useful when you want to ensure that an element does not exceed a certain width, regardless of the size of its container or its content.
Utility Class | USS Properties |
---|---|
max-w-0 | max-width: 0px; |
max-w-1 | max-width: 4px; |
max-w-2 | max-width: 8px; |
max-w-3 | max-width: 12px; |
max-w-4 | max-width: 16px; |
max-w-5 | max-width: 20px; |
max-w-6 | max-width: 24px; |
max-w-7 | max-width: 28px; |
max-w-8 | max-width: 32px; |
max-w-9 | max-width: 36px; |
max-w-10 | max-width: 40px; |
max-w-11 | max-width: 44px; |
max-w-12 | max-width: 48px; |
max-w-14 | max-width: 56px; |
max-w-16 | max-width: 64px; |
max-w-20 | max-width: 80px; |
max-w-24 | max-width: 96px; |
max-w-28 | max-width: 112px; |
max-w-32 | max-width: 128px; |
max-w-36 | max-width: 144px; |
max-w-40 | max-width: 160px; |
max-w-44 | max-width: 176px; |
max-w-48 | max-width: 192px; |
max-w-52 | max-width: 208px; |
max-w-56 | max-width: 224px; |
max-w-60 | max-width: 240px; |
max-w-64 | max-width: 256px; |
max-w-72 | max-width: 288px; |
max-w-80 | max-width: 320px; |
max-w-96 | max-width: 384px; |
max-w-px | max-width: 1px; |
max-w-0point5 | max-width: 2px; |
max-w-1point5 | max-width: 6px; |
max-w-2point5 | max-width: 10px; |
max-w-3point5 | max-width: 14px; |
max-w-none | max-width: none; |
max-w-xs | max-width: 320px; |
max-w-sm | max-width: 384px; |
max-w-md | max-width: 448px; |
max-w-lg | max-width: 512px; |
max-w-xl | max-width: 576px; |
max-w-2xl | max-width: 672px; |
max-w-3xl | max-width: 768px; |
max-w-4xl | max-width: 896px; |
max-w-5xl | max-width: 1024px; |
max-w-6xl | max-width: 1152px; |
max-w-7xl | max-width: 1280px; |
max-w-full | max-width: 100%; |
max-w-screen-sm | max-width: 640px; |
max-w-screen-md | max-width: 768px; |
max-w-screen-lg | max-width: 1024px; |
max-w-screen-xl | max-width: 1280px; |
max-w-screen-2xl | max-width: 1536px; |
Usage
To use the Max-Width
utility, apply the class max-w-{size}
to an element. For example, max-w-md
sets the maximum width to 768 pixels.
<ui:VisualElement class="max-w-md">
<!-- Element with a maximum width of 768px -->
</ui:VisualElement>
The sm
, md
, lg
, xl
, and 2xl
sizes refer to screen size breakpoints. The none
size removes the maximum width.
Customize
Modifier Variations
You can customize which modifier variations of the Max-Width
utility are generated, such as pseudo-classes (e.g., hover
, focus
) and custom modifiers.
Max-Width
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
Max-Width
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 Max-Width
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 Max-Width
utility:
- max-w : max-width
To customize these tags and properties, you can edit the Tag Property Map
field for the Max-Width
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 Max-Width
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
Max-Width
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 Max-Width
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.