Home > Web Front-end > CSS Tutorial > How to Rotate Text 90 Degrees in HTML Tables with Adjustable Cell Size?

How to Rotate Text 90 Degrees in HTML Tables with Adjustable Cell Size?

Mary-Kate Olsen
Release: 2024-10-31 05:10:02
Original
465 people have browsed it

How to Rotate Text 90 Degrees in HTML Tables with Adjustable Cell Size?

How to Rotate Text 90 Degrees with Adjustable Cell Size in HTML

When rotating text in HTML tables, it's common to encounter challenges in maintaining cell size consistency. To address this, let's explore a solution that employs CSS and HTML without the need for complex height calculations.

The trick lies in using the vertical-align and text-align CSS properties to adjust the text orientation within table cells. Additionally, we'll utilize the -ms-writing-mode, -webkit-writing-mode, and writing-mode properties to enable vertical text writing.

To achieve a 90-degree rotation, we apply a transform: rotate(180deg); to ensure that the text appears vertically. Note that this technique may not work perfectly in all browsers, particularly Chrome, which requires the use of elements to correct the text direction for table headers ().

Here's a practical example to demonstrate:

<code class="css">th {
  vertical-align: bottom;
  text-align: center;
}

th span {
  -ms-writing-mode: tb-rl;
  -webkit-writing-mode: vertical-rl;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}</code>
Copy after login
<code class="html"><table>
  <tr>
    <th><span>Rotated text by 90 deg.</span></th>
  </tr>
</table></code>
Copy after login

This approach allows for the rotation of text in table cells while preserving the desired cell size. Embrace this technique for hassle-free vertical text display in your HTML tables, ensuring that your data is presented clearly and elegantly.

The above is the detailed content of How to Rotate Text 90 Degrees in HTML Tables with Adjustable Cell Size?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template