You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用writing-mode: vertical-rl实现垂直按钮时Safari移动端文字截断问题

问题根因

Safari 浏览器对 writing-mode: vertical-rl 垂直书写模式的元素尺寸计算存在原生兼容缺陷,当垂直文本被 flex、grid 容器包裹时,无法正确计算容器的自适应宽高,最终导致文本溢出、被容器截断。

修复步骤

你可以按照以下规则修改CSS代码解决问题:

  • 为垂直文本元素添加 -webkit-writing-mode 前缀属性适配 Safari 内核,同时添加 text-orientation: mixed 适配多语种的字符朝向
  • 调整文本按钮的布局规则,将 display: grid 替换为 display: flex 避免布局冲突,显式指定 width: fit-content 开启宽高自适应
  • 移除外层容器不必要的尺寸限制,修正固定定位下的尺寸计算逻辑

修复后完整CSS代码

body {
  height: 100%;
  width: 100%;
}

.wrapper.center-right {
  cursor: pointer;
  position: fixed;
  height: auto;
  width: auto;
  margin: 0;
  padding: 0;
  display: flex;
  z-index: 2147483647;
  background: red;
  top: 50%;
  flex-direction: column;
  right: 0;
  transform: translate(0, -50%);
  transform-origin: right top;
}

.wrapper.center-right .text-button {
  width: fit-content;
  min-width: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wrapper.center-right .text-button .text {
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 8px 4px;
  margin: 0;
  max-height: 150px;
  overflow-y: auto;
}

.text-button,
.close-btn {
  border: solid 2px red;
  outline: none;
  box-sizing: border-box;
}

.text-button:focus,
.close-btn:focus  {
  color: blue;
  outline: none;
  border: blue solid 2px;
}

.text-button:focus .button-text {
  color: blue;
}

修复效果说明

修改后代码可同时兼容 Chrome、Safari 桌面端及移动端,动态长度的多语种垂直文本可正确撑开容器,不会出现溢出截断问题,横向展示模式也可通过切换书写模式属性正常适配。

内容的提问来源于stack exchange,提问作者Megi Ben Nun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.13 19:15:01