Utilities
Utilities
From spacing to display, Seattle Times UI kit provides a suite of utility classes that help layout your UIs quickly and easily.
Naming Conventions
Utility classes do not have a single defined naming convention. Instead, names are created with the following considerations:
- readability - can you have a reasonable idea of what the class will do just from the name?
- succinctness - will chaining several utility classes on an element make it unreadably long?
- uniqueness - generally try to avoid using the same abbreviation to represent different properties, classes that are just a common word, such as
white
should be prefixed withu-
to avoid naming collisions and so they can be found in the future
Spacing
You can assign responsive utility classes to your element’s sides to add padding
and margin
values. This includes support for all properties, individual properties, or horizontal and vertical properties. The spacing is configurable as variables.
Naming
Classes are named using the format {property}{side}{-screen}-{size}
.
Property is one of:
m
- set themargin
propertyp
- set thepadding
property
Side is one of:
- (blank) all four sides of the element
r
- rightl
- leftt
- topb
- bottomh
- horizontalv
- vertical
Screen is one of:
- (blank) all screen sizes
sm
- small screen and largermd
- medium screen and largerlg
- large screen and largerxl
- extra large screen and larger
Size is one of:
0
- set the property to0
1
- set the property to the value of$spacer-xs
2
- set the property to the value of$spacer-sm
3
- set the property to the value of$spacer-md
4
- set the property to the value of$spacer-lg
5
- set the property to the value of$spacer-xl
auto
- set the property to the value ofauto
(used formargin
only)
Examples
Here is a sampling of some of the classes and the resulting styles:
Configure
The values of $breakpoints
and $spacer-*
are set in the _variables.scss
partial and can be customized to your liking. You may want to create some additional sizes and extend these utility classes to include more granular spacing classes like *-6
and *-7
.
Display
Any display styles you might apply to your components can also be done with utility classes.
Classes are named using the format u-d{value-initials}
.
.u-db
- set the property toblock
.u-di
- set the property to the value ofinline
.u-dib
- set the property to the value ofinline-block
.u-dit
- set the property to the value ofinline-table
.u-dt
- set the property to the value oftable
.u-dtr
- set the property to the value oftable-row
.u-dtc
- set the property to the value oftable-cell
.u-df
- set the property to the value offlex
.u-dif
- set the property to the value ofinline-flex
Hiding
There are a set of responsive hiding utility class you can add to any component. Classes are named using the format hide{-screen}
Additionally, there are some visually hidden classes that can be used for screen readers or other purposes. Classes are named using the format visually-hide{-screen}
With both sets of classes, screen is one of:
- (blank) all screen sizes
xs
- extra small screen onlysm
- small screen onlymd
- medium screen onlylg
- large screen onlyxl
- extra large screen only
Use visually-hide-focusable
to allow visually hidden elements to become visible upon active or focus state.
The overflow shorthand CSS property sets what to do when an element’s content is too big to fit in its block formatting context. It is a shorthand for overflow-x and overflow-y.
.u-ofh
- sets the overflow to hidden
Z-index
The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order. Note: z-index only works on positioned elements (position: absolute, position: relative, position: fixed, or position: sticky).
.z-1
- sets the z-index to 1.z-2
- sets the z-index to 2.z-3
- sets the z-index to 3.z-4
- sets the z-index to 4.z-5
- sets the z-index to 5.z-6
- sets the z-index to 6
Floats
Three classes let you quickly set the float property.
.u-fl
- set the property toleft !important
.u-fr
- set the property toright !important
.u-fn
- set the property tonone !important
To clear your floats, you can use the .clearfix
class.
Position
Set the position of an element to relative or fixed. Note that u-fixed
is useful for toggling the fixed state of an element, which is why it also uses !important
.
.u-fixed
- set the property toposition: fixed !important
.u-relative
- set the property toposition: relative
.u-absolute
- set the property toposition: absolute
Width & Height
Set elements width and height properties.
.u-mw-100-pct
- sets the property tomax-width: 100%
.u-w-100-pct
- sets the property towidth: 100%
.u-w-74-vw
- sets the property towidth: 74vw
.u-h-50-px
- sets the property toheight: 50px
Color
Color utilities set the color
or background-color
of an element and the color
and background-color
of an element on hover
, focus
, and active
states. These class names are prefixed with a u-
for utility to avoid naming conflicts and enable searching.
For example:
Color names are defined in $colors
in _variables.scss
. To generate more color utilities, simply add values to the map and utilities for the color, background-color, and hover-focus-active states of color and background-color will be generated. Another option is to add utilities that describe state as opposed to a specific color value. For example, is-error
and is-success
if you want the flexibility to change which color represents a state without changing markup.
Cursor
The cursor property specifies the mouse cursor to be displayed when pointing over an element.
Font
Font utilities set common font and type characteristics, such as font-family
, font-size
, and text-align
.
Font Families
Font Weights
Font Size and Line Height Pairings
At this time, since line heights and font sizes are defined individually, each font size utility class also sets the corresponding line height.
The .font-*
class corresponds to variables created in _variables.scss
. These classes set both font size and line height.
Note: the difference in line height from .font-micro
Note: the difference in line height from .font-xtiny
Other pairings
These size pairings show up around seattletimes.com, but they might not have a utility class.
Line Height
1 em Line Height (.u-lh-1-em) Morbi sit amet gravida nunc, nec fringilla erat.
2 em Line Height (.u-lh-2-em) Morbi sit amet gravida nunc, nec fringilla erat.
23 px Line Height (.u-lh-23-px) Morbi sit amet gravida nunc, nec fringilla erat.
Transforms and Decorations Families
Horizontal Alignment
Vertical Alignment
Top Aligned (.u-vt)
Middle Aligned (.u-vm)
Bottom Aligned (.u-vb)
Set a hover color for a link
This currently only sets a hover color, although we could add to this so it does more
Letter Spacing
Prevent Text From Wrapping
White space: no wrap (.u-ws-nowrap)
This paragraph doesn't wrap. Morbi sit amet gravida nunc, nec fringilla erat.
But all the other paragraphs still wrap.
Morbi sit amet gravida nunc, nec fringilla erat.
Borders
The base border classes set border-style: solid
and border-width: 1px
on each or all sides of an element. By default border-color
is inherited from the element’s color but you can also set the border-color
explicitly with .u-border-{$color}
classes. Border colors are defined in $border-colors
in _variables.scss
.
Flex
A set of flex utility classes that should allow you to do most flexbox layouts without writing any new CSS.
Layout
Use $grid-columns
, $grid-gutter-width
, and $grid-container-max-width
defined in _variables.scss
to generate a customized, flex-based column layout.