旋转的文本产生不一致的结果
Rotated text producing inconsistent results
我正在尝试显示旋转文本,它始终绝对定位在其父项的底部。父项是浏览器 window 的 100% 高度,对于所有 browser/screen 大小,我希望文本从底部显示 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/ 这是我要实现的目标的图片:
当你放置旋转时:-90px
真正的底部是左边
真正的权利是底部
那么我们可以说:
bottom -> right
right -> top
top -> left
left -> bottom
但是当你把这里
left: 0px;
它不是真的0px;
因为在水平位置从div的中心计算
你的代码是正确的
像这样
.carousel a.item h1 {
color: #fff;
font-size: 15px;
font-weight: 400;
position: absolute; bottom:10px; left: 150px;
height: 100%;
width: 100%;
background: blue;
z-index: 5;
display: block;
}
您需要像这样调整 transform-origin 和 .rotate
元素的位置:
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 {
white-space: nowrap;
position: absolute;
bottom: 50px;
left: 100%;
transform-origin: left bottom;
transform: rotate(-90deg);
}
.carousel a.item h1 {
color: #fff;
}
.bg-image {
background-repeat: no-repeat;
background-position: center center;
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.
试试这个,只需将 <br>
放在代码中:
<div class="rotate">
<h1>Short but also longer but not to long</h1>
<br>
</div>
您不需要绝对定位旋转元素的内容。
只需调整变换和变换原点即可。
.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>
我正在尝试显示旋转文本,它始终绝对定位在其父项的底部。父项是浏览器 window 的 100% 高度,对于所有 browser/screen 大小,我希望文本从底部显示 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/ 这是我要实现的目标的图片:
当你放置旋转时:-90px
真正的底部是左边
真正的权利是底部
那么我们可以说:
bottom -> right
right -> top
top -> left
left -> bottom
但是当你把这里
left: 0px;
它不是真的0px;
因为在水平位置从div的中心计算
你的代码是正确的
像这样
.carousel a.item h1 {
color: #fff;
font-size: 15px;
font-weight: 400;
position: absolute; bottom:10px; left: 150px;
height: 100%;
width: 100%;
background: blue;
z-index: 5;
display: block;
}
您需要像这样调整 transform-origin 和 .rotate
元素的位置:
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 {
white-space: nowrap;
position: absolute;
bottom: 50px;
left: 100%;
transform-origin: left bottom;
transform: rotate(-90deg);
}
.carousel a.item h1 {
color: #fff;
}
.bg-image {
background-repeat: no-repeat;
background-position: center center;
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.
试试这个,只需将 <br>
放在代码中:
<div class="rotate">
<h1>Short but also longer but not to long</h1>
<br>
</div>
您不需要绝对定位旋转元素的内容。
只需调整变换和变换原点即可。
.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>