CSS对齐旋转文本

时间:2020-07-10 13:57:33

标签: css rotation right-align

我在div中有一个旋转的文本。我想将跨度对齐到div的“右”(见红色箭头)

<div class="rotateText">
  <span>This is a rotated multiline text please display it in a correct way. This is a rotated multiline text please display it in a correct way</span>
</div>

    .rotateText{
      width: 200px;
      height: 300px;
      writing-mode: tb-rl;
      transform: rotate(-180deg);
      background-color: yellow;
    }

https://jsfiddle.net/konqmr8c/1/

enter image description here

4 个答案:

答案 0 :(得分:0)

使用position: absolute可以很简单地做到这一点。将relative应用于父容器,以便可以将跨度锚定到其上,然后设置left: 0。这将使文本紧贴容器的底部。

.rotateText{
  width: 200px;
  height: 300px;
  writing-mode: tb-rl;
  transform: rotate(-180deg);
  background-color: yellow;
  position: relative;
}

span {
  position: absolute;
  left: 0;
}

这将导致以下结果:

Rotated

如果您只想旋转整个盒子,只需删除transform属性。结果:

enter image description here

答案 1 :(得分:0)

.rotateText{
  width: 200px;
  height: 300px;
  writing-mode: tb-rl;
  transform: rotate(-180deg);
  background-color: yellow;
  position:relative;
}

span {
  border:1px solid red;
  position:absolute;
  left: 0px;
}

答案 2 :(得分:0)

您可能不需要一个额外的容器, logOut() { this.oidcSecurityService.logoffLocal(); this.oidcSecurityService.logoffAndRevokeTokens(); this.oidcSecurityService.logoff(); // none of the three mentioned above work. } flexwriting-mode应该这样做。对于某些浏览器,align-items缺失的情况将要求进行转换,以在另一侧将其重置。

writing-mode:sideways-lr
.rotateText {
  width: 200px;
  height: 300px;
  display: flex;
  background-color: yellow;
  align-items: flex-end;
  /* 
  writing-mode:sideways-lr; 
 ... would be great if that worked everywhere ,
 let's use what's avalaible and transform :*/
  writing-mode: tb-rl;
  transform: scale(-1)
}

.rotateText.column {
  /* if a few child, you need to reset direction and alignement */
  flex-direction: column;
  justify-content: flex-end;
  align-items: start
}


/* demo purpose */

.rotateText {
  float: left;
  margin: 0.5em;
}

h1,
p {
  margin: 0.15em;
}

答案 3 :(得分:-1)

Flexbox可以做到这一点:

请注意,writing-modetransform应该在上,而不是父上。

.rotateText {
  width: 200px;
  height: 300px;
  display: flex;
  background-color: yellow;
  justify-content: flex-end;
}

span {
  writing-mode: tb-rl;
  transform: rotate(180deg);
}
<div class="rotateText">
  <span>This is a rotated multiline text please display it in a correct way. This is a rotated multiline text please display it in a correct way</span>
</div>