Description
The OnlyChild
field is a member of the Sandbox.UI.PseudoClass
enumeration. It represents the CSS pseudo-class :only-child
, which is used to select an element that is the only child of its parent element. This pseudo-class is useful in styling scenarios where you want to apply specific styles to elements that do not have any siblings.
Usage
Use the OnlyChild
pseudo-class in your UI styling logic to target elements that are the sole child of their parent. This can be particularly useful for applying unique styles or layout adjustments to elements that do not have any sibling elements.
Example
// Example usage in a UI component
public class MyComponent : Panel
{
public MyComponent()
{
// Apply a style to elements that are the only child of their parent
StyleSheet.Add(
".my-element:only-child",
new Style { BackgroundColor = Color.Red }
);
}
}