


How to Prevent CSS Rotated Elements from Overlapping Other Elements?
Dec 13, 2024 am 02:11 AMRotated Elements in CSS that Align Vertically
In CSS, you can use the writing-mode property to rotate text vertically. However, rotating text can affect the positioning of its parent elements. This can lead to unexpected results, such as text overlapping other elements.
Problem:
Consider the following example:
<div class="container"> <div class="statusColumn"><span>Normal</span></div> <div class="statusColumn"><a>Normal</a></div> <div class="statusColumn"><b>Rotated</b></div> <div class="statusColumn"><abbr>Normal</abbr></div> </div>
.statusColumn b { writing-mode: tb-rl; white-space: nowrap; display: inline-block; overflow: visible; transform: rotate(-90deg); transform-origin: 50% 50%; }
This code results in the following layout:
[Image of text in four columns, with the third column rotated 90 degrees]
As you can see, the rotated text overlaps the other elements.
Solution:
To fix this issue, you can use the writing-mode property on the parent element to rotate the text vertically. This will ensure that the rotated text aligns correctly within the parent element.
.statusColumn { position: relative; border: 1px solid #ccc; padding: 2px; margin: 2px; width: 200px; } .statusColumn i, .statusColumn b, .statusColumn em, .statusColumn strong { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; display: inline-block; overflow: visible; }
This code results in the following layout:
[Image of text in four columns, with the third column rotated vertically]
As you can see, the rotated text is now aligned vertically within the parent element, and does not overlap the other elements.
The above is the detailed content of How to Prevent CSS Rotated Elements from Overlapping Other Elements?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Adding Box Shadows to WordPress Blocks and Elements

Create a JavaScript Contact Form With the Smart Forms Framework

Making Your First Custom Svelte Transition

Demystifying Screen Readers: Accessible Forms & Best Practices

Comparing the 5 Best PHP Form Builders (And 3 Free Scripts)
