Home > Web Front-end > CSS Tutorial > How Can I Make Rotated CSS Elements Correctly Influence Their Parent's Height?

How Can I Make Rotated CSS Elements Correctly Influence Their Parent's Height?

Mary-Kate Olsen
Release: 2024-12-12 12:00:32
Original
276 people have browsed it

How Can I Make Rotated CSS Elements Correctly Influence Their Parent's Height?

Rotated Elements in CSS: Influencing Parent Height Correctly

In CSS, it's possible to rotate elements without affecting the layout or flow of the document. However, questions arise when elements need their rotated text to impact their parent's height.

Consider the following scenario:

<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>
Copy after login

Applying the following CSS:

.statusColumn b {
  writing-mode: tb-rl;
  white-space: nowrap;
  display: inline-block;
  overflow: visible;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}
Copy after login

Results in the rotated text overlapping neighboring elements. The goal is to modify the CSS to ensure that the rotated element correctly affects its parent's height, preventing text overlap.

Solution

Taking advantage of the improved support for writing-mode in modern browsers, a solution can be achieved using a combination of properties:

.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;
}
Copy after login

This updated CSS ensures that the rotated element respects the height of its parent container, thus preventing text overlap and achieving the desired layout.

The above is the detailed content of How Can I Make Rotated CSS Elements Correctly Influence Their Parent's Height?. 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