Table of Contents
Alignment + Click Target
In the context of design, the use of straight lines & right angles communicate that it has been crafted by a human. That it has been designed. Nature doesn't use them. When creating a webpage, it is easy to create layouts constructed with straight lines & right angles. However, when we need to incorporate click-target size requirements, layouts can lose their alignment. Below defails an approach that fulfills these requirements without breaking alignment.
Imagine we need to code the layout for a web page. It will have 3 root elements:
- ▪ a back link in the top left,
- ▪ a list below the link &
- ▪ a section for content to the right.
Elements should be positioned so:
- ▪ the link & list items' text should align vertically,
- ▪ the link & main's text baselines should align horizontally,
16pxspace between elements & between elements and page border.
2. Add Content
Add the contents to the page & remove any excess white-space. To achieve this:
- ▪ set all margins & padding to
- ▪ use Capsize to generate the CSS required to trim unwanted vertical space above & below text.
<body/> will be acting as a layout component.
I believe a trait of a good layout component is it adapts to its contents.
I'm using a CSS grid to position the root elements.
The left column's width is set to
auto, enabling it to adapt to the link & list's contents.
The right is set to
1fr, filling the remaining width of the layout.
3. Add Space
Add space between elements:
<ol/>'s flex container.
Visually, we are now fulfilling all requirements.
4. Increase Click-Target
Unfortunatley, there is an accessibility problem with the link.
The size of the clickable area is only
The recommended minimums are:
44pxfor AAA rating.
24pxfor AA rating. This can be reduced to
- ▫ the area is inline (such as a a link within a paragraph) or
- ▫ there is a minimum
4pxgap between adjacent clickable areas.
1 approach to fix this is to add padding to the link:
Although this has fixed the accessibility problem, it has broken the layout's alignment:
- ▪ the link & list items' text no longer align vertically,
- ▪ the link & main's text no longer align horizontally &
- ▪ the space between the left & right columns has increased beyond
16px. Calculated from the right-most letter in the left column to the left-most letter in the right column.
5. Alignment Fix
We can use a different approach that will solve both the accessibility problem while maintaining the layout's alignment. Instead of adding padding, add an absolutley positioned pseudo-element to the link. This allows setting a click target to any size without effecting the positioning of the link or its adjacent elements.
As capsize makes use of pseudo-elements, the link's text is moved into a
<span> to prevent styles interfering with each other.
We now have a layout that adapts to its content, has alignment across all elements & passes accessibility requirements.