Vertical (rotated) text in HTML table
Use CSS transform: rotate(-90deg);
on a div
within your table cell to vertically display text.
The transform: rotate(-90deg);
rotates your text 90 degrees left, ideal when you have slender table headers needing a little twist. white-space: nowrap;
keeps your text from wrapping, ensuring crisp, clean vertical lines.
For cross-browser compatibility, remember the -webkit-transform
and -ms-transform
tags:
To rotate like a text gymnast, apply the .box_rotate
class to your div
:
Always test your text pirouetting across different browsers and devices and modify for long headings to fit with the page layout.
Applying rotation to header text
Use the same .box_rotate
class to vertically rotate your header text to solve table layout challenges.
Handling extended content
When words start to go the distance:
- Abbreviate content: Words are like cake, sometimes a slice is enough.
- Font-size alteration: Like your favourite band, fonts sometimes need to go small.
- Change the angle: Adjust to
-45deg
or-60deg
; you're the Picasso of your table design.
Accessibility focus
Disability is a matter of perception. Structure your HTML to be understandable for assistive technologies and screen readers.
This design not only looks good but also communicates well.
Designing for mobile users
Think small for big usability.
- Media Queries: hear the call and answer with rotate only on larger screens.
- Flexible, not fixed, sizing: build for gadgets both big and small with adjustable sizes.
Anticipating potential pitfalls and solutions
Consider this section your CSS stunt double.
- Alignment: CSS acting up? Use
text-align
andvertical-align
to straighten it out. - Overlap: If rotated text overlaps, make your table layout more flexible or loosen the font waistband with a smaller
font-size
. - Hover: Be wary of hover styling quirks that can cause visual confusion when text is rotated.
Test the waters before taking the plunge to ensure a happy balance of form and function.
Was this article helpful?