css - 旋转的文本产生不一致的结果

标签 css rotation css-transforms

我正在尝试显示旋转文本,因此它始终绝对定位到其父项的底部。父级是浏览器窗口的 100% 高度,对于所有浏览器/屏幕尺寸,我希望文本从底部显示 50px。

这是我的代码:

html,body,.carousel,.carousel a.item { height: 100%; }
.carousel a.item {
  height: 100%;
  padding-top: 100px;
  position: relative;
  overflow: hidden;
  width: 25%;
  float: left;
}
.rotate {
  zoom: 1;
  white-space: nowrap;
  position: absolute;
  bottom: 0;
  right: 0;
  z-index: 3;
  display: block;
  width: 100%;
  background: pink;
  -webkit-transform-origin: right bottom;
  -moz-transform-origin: right bottom;
  -o-transform-origin: right bottom;
  -ms-transform-origin: right bottom;
  transform-origin: right bottom;
  -webkit-transform: rotate(-90deg);
  -moz-transform: rotate(-90deg);
  -o-transform: rotate(-90deg);
  -ms-transform: rotate(-90deg);
  transform: rotate(-90deg);
}
.carousel a.item h1 {
  color: #fff;
  position: absolute;
  right: 0;
  bottom: 0;
  height: 100%;
  width: 100%;
  background: blue;
  z-index: 5;
  display: block;
}
.bg-image {
  background-repeat: no-repeat;
  background-position: center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
<div class="carousel">
  <a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
    <div class="rotate">
      <h1>Some really long title thats quite long. Did I say it was long?</h1>
    </div>
  </a>
  <a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
    <div class="rotate">
      <h1>This is really short</h1>
    </div>
  </a>
  <a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
    <div class="rotate">
      <h1>Short but also longer but not to long</h1>
    </div>
  </a>
  <a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
    <div class="rotate">
      <h1>Some really long title thats quite long. Did I say it was long?</h1>
    </div>
  </a>

</div>

到目前为止,我的代码有一个 fiddle 设置:https://jsfiddle.net/77xzfsfa/这是我想要实现的目标的图像:

enter image description here

最佳答案

您不需要绝对定位旋转元素的内容。

只需调整变换和变换原点即可。

.rotate{
    zoom: 1;
  white-space: nowrap;
  position: absolute;
  z-index: 3;
  display: inline-block;
  position: absolute;
  right: 0;
  bottom: 50px;
  transform:translate(100%,0%) rotate(-90deg);
  transform-origin:bottom left;
}


.carousel a.item h1 {
    color: #fff;
    z-index: 5;
}

* {
  margin: 0;
}
html,
body,
.carousel,
.carousel a.item {
  height: 100%;
}
.carousel a.item {
  height: 100%;
  padding-top: 100px;
  position: relative;
  overflow: hidden;
  width: 25%;
  float: left;
}
.rotate {
  zoom: 1;
  white-space: nowrap;
  position: absolute;
  z-index: 3;
  display: inline-block;
  position: absolute;
  right: 0;
  bottom: 50px;
  transform: translate(100%, 0%) rotate(-90deg);
  transform-origin: bottom left;
}
.carousel a.item h1 {
  color: #fff;
  z-index: 5;
}
.bg-image {
  background-repeat: no-repeat;
  background-position: center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
<div class="carousel">
  <a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
    <div class="rotate">
      <h1>Some really long title thats quite long. Did I say it was long?</h1>
    </div>
  </a>
  <a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
    <div class="rotate">
      <h1>This is really short</h1>
    </div>
  </a>
  <a href="#" class="item bg-image" style="background-image: url('https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97800&w=300&h=800');">
    <div class="rotate">
      <h1>Short but also longer but not to long</h1>
    </div>
  </a>
  <a href="#" class="item bg-image" style="background-image: url('http://www.freelargeimages.com/wp-content/uploads/2014/12/Landscape_01.jpg');">
    <div class="rotate">
      <h1>Some really long title thats quite long. Did I say it was long?</h1>
    </div>
  </a>

</div>

关于css - 旋转的文本产生不一致的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34746173/

相关文章:

css - IE8 - 背景不正确显示背景位置和 float 属性

javascript - 悬停背景(放大),前面的文字没有放大

css - 无法在 AngularJS ui-view 中居中链接

html - 等待 'background-image' css 样式完全加载

css - 带有多个父选择器的 SASS @at-root

c# - 是否有一种算法(名称、实现)给出两个相同排序/内容但不同起始项的列表来测试是否相等?

css - 旋转带有文本的 div。 Safari 的问题

python - OpenGL正确的矩阵变换顺序以在定点旋转对象

html - 为什么在此 CSS 转换过程中存在明显的滞后?

html - 浏览器之间背面可见性的行为不一致