How to Rotate Text in CSS Without Alignment Issues
To achieve the text rotation as shown in the image provided, CSS transforms can be utilized. However, doing so often results in misalignment and positioning problems. This issue arises because the rotation affects the element's position in the flow.
In the provided HTML, multiple titles and content sections are nested within a container. To rotate the titles, the transform: rotate(-90deg) property is applied. However, this rotation disrupts the alignment of the content because it is assumed that the content flows horizontally after the title.
Causes of Alignment Issues
Solution: Preserving Alignment
To maintain proper alignment, we can use the following strategies:
1. Vertical Flow:
Example:
<code class="css">.title { display: block; writing-mode: vertical-rl; transform: rotateZ(-90deg) /* or transform: rotate(-90deg) */; } .content { writing-mode: horizontal-tb; }</code>
2. Absolute Positioning:
Example:
<code class="css">.title { position: absolute; transform: rotate(-90deg); top: 0; bottom: 0; } .content { margin-left: 50px /* adjust the margin to align with the rotated title */; }</code>
By using these methods, you can rotate text in CSS while preserving the alignment and positioning of adjacent elements.
The above is the detailed content of How to Rotate Text in CSS Without Alignment Issues?. For more information, please follow other related articles on the PHP Chinese website!