我正在尝试显示旋转文本,因此它始终绝对定位到其父项的底部。父级是浏览器窗口的 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/这是我想要实现的目标的图像:
最佳答案
您不需要绝对定位旋转元素的内容。
只需调整变换和变换原点即可。
.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/