liveBook · Manning

Vertical-align property

As explained in Tiny CSS Projects

The CSS vertical-align property controls the vertical alignment of an inline or inline-block element relative to surrounding inline content.

The CSS vertical-align property aligns an inline or inline-block element vertically according to the surrounding inline content. Use the value middle when an image needs to sit centrally inside a button. section 8.2.2

Centering an image in a Remove button

A circular destructive button uses reduced padding so it does not dominate the cart table. Applying vertical-align: middle to its image centers the image vertically inside the button. section 8.2.2

Listing 8.6 Remove button
button.destructive {
  border-color: #9d1616;
  color: #9d1616;
  border-radius: 50%;
  padding: 5px;
}
 
button.destructive img {     #1
  vertical-align: middle;    #1
}                            #1
 
button.destructive:hover,
button.destructive:focus {
  outline-color: #9d1616;
}

Inspect the complete destructive-button rule, including the vertical-align declaration and its hover and focus styling. section 8.2.2

How Tiny CSS Projects covers it

How deep it goes
Defines alignment for inline and inline-block elements, then applies middle to a button image without exploring other values.
Examples
Demonstrates centering an image inside a circular Remove button in a checkout cart.
What you can do after
Apply it via CSS to center an image vertically within a button.
How it connects
Connects inline elements, inline-block elements, images, buttons, and vertical alignment.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.