Home > Web Front-end > CSS Tutorial > How to Rotate Text in HTML Tables Without Distorting Cell Size?

How to Rotate Text in HTML Tables Without Distorting Cell Size?

Linda Hamilton
Release: 2024-10-29 22:49:02
Original
429 people have browsed it

How to Rotate Text in HTML Tables Without Distorting Cell Size?

Using CSS to Rotate Text and Adjust Cell Size in HTML Tables

When attempting to rotate text in table cells, it's important to also consider the impact on the cell size. As illustrated in the provided example, when using CSS transforms to rotate text without adjusting the cell size, the result can be distorted.

To resolve this issue, adjustments to the table and cell styles are necessary. By setting vertical-align: bottom and text-align: center for table headers (th), the text is positioned correctly after rotation.

For Chrome specifically, it's necessary to wrap the rotated text within a element. This ensures that the text's direction is also changed, preventing horizontal text from appearing after rotation. The span element is subsequently styled with -ms-writing-mode: tb-rl, -webkit-writing-mode: vertical-rl, writing-mode: vertical-rl, transform: rotate(180deg), and white-space: nowrap.

Example Code

<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

By implementing these style adjustments, it becomes possible to rotate text by 90 degrees while maintaining proper cell size and formatting.

The above is the detailed content of How to Rotate Text in HTML Tables Without Distorting 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