我想将单个文本单词旋转90度,支持跨浏览器(>= IE6, >= Firefox 2,任何版本的Chrome, Safari或Opera)。如何做到这一点呢?
当前回答
更新这个答案与最近的信息(从CSS技巧)。感谢Matt和Douglas指出了过滤器实现。
.rotate {
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
/* also accepts left, right, top, bottom coordinates; not required, but a good idea for styling */
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
transform-origin: 50% 50%;
/* Should be unset in IE9+ I think. */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
旧的回答:
对于FF 3.5或Safari/Webkit 3.1,请检查:-moz-transform(和-webkit-transform)。IE有一个矩阵过滤器(v5.5+),但我不确定如何使用它。Opera还没有转换功能。
.rot-neg-90 {
/* rotate -90 deg, not sure if a negative number is supported so I used 270 */
-moz-transform: rotate(270deg);
-moz-transform-origin: 50% 50%;
-webkit-transform: rotate(270deg);
-webkit-transform-origin: 50% 50%;
/* IE support too convoluted for the time I've got on my hands... */
}
其他回答
我改编自http://snook.ca/archives/html_and_css/css-text-rotation:
<style> .Rotate-90 { display: block; position: absolute; right: -5px; top: 15px; -webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); } </style> <!--[if IE]> <style> .Rotate-90 { filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); right:-15px; top:5px; } </style> <![endif]-->
如果CSS写作模式:sideway -lr是你喜欢的,而你恰巧遇到了基于chromium/chrome的浏览器。你可以试试
{
writing-mode: vertical-rl;
transform: rotate(180deg);
}
所以现在所有的浏览器都支持它。
参考:https://bugs.chromium.org/p/chromium/issues/detail?id=680331 c4
更新这个答案与最近的信息(从CSS技巧)。感谢Matt和Douglas指出了过滤器实现。
.rotate {
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
/* also accepts left, right, top, bottom coordinates; not required, but a good idea for styling */
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
transform-origin: 50% 50%;
/* Should be unset in IE9+ I think. */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
旧的回答:
对于FF 3.5或Safari/Webkit 3.1,请检查:-moz-transform(和-webkit-transform)。IE有一个矩阵过滤器(v5.5+),但我不确定如何使用它。Opera还没有转换功能。
.rot-neg-90 {
/* rotate -90 deg, not sure if a negative number is supported so I used 270 */
-moz-transform: rotate(270deg);
-moz-transform-origin: 50% 50%;
-webkit-transform: rotate(270deg);
-webkit-transform-origin: 50% 50%;
/* IE support too convoluted for the time I've got on my hands... */
}
如果你使用Bootstrap 3,你可以使用它的一个mixins:
.rotate(degrees);
例子:
.rotate(-90deg);
我的解决方案,将工作在Chrome, Firefox, IE9, IE10(改变度根据您的要求):
.rotate-text {
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-ms-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
filter: none; /*Mandatory for IE9 to show the vertical text correctly*/
}
推荐文章
- 如何以及在哪里使用::ng-deep?
- Angular 2模板中的标签是什么意思?
- 如何设置身体高度溢出滚动
- 在输入type="number"时禁用webkit的旋转按钮?
- 如何在另一个元素之后添加一个元素?
- 我如何有效地解析HTML与Java?
- “ ”和“”有什么区别?
- 如何使用JavaScript代码获得浏览器宽度?
- 防止滚动条增加到Chrome页面的宽度
- 使用图像而不是单选按钮
- 将RGB转换为白色的RGBA
- 我可以嵌套一个<按钮>元素内< >使用HTML5?
- 设置TextView文本从html格式的字符串资源在XML
- 为什么我的球(物体)没有缩小/消失?
- Twitter Bootstrap 3 Sticky Footer