我想将单个文本单词旋转90度,支持跨浏览器(>= IE6, >= Firefox 2,任何版本的Chrome, Safari或Opera)。如何做到这一点呢?
当前回答
另一种解决方案是使用大多数浏览器都支持的SVG文本节点。
<svg width="50" height="300">
<text x="28" y="150" transform="rotate(-90, 28, 150)" style="text-anchor:middle; font-size:14px">This text is vertical</text>
</svg>
演示:https://jsfiddle.net/bkymb5kr/
关于SVG文本的更多信息:http://tutorials.jenkov.com/svg/text-element.html
其他回答
如果你使用Bootstrap 3,你可以使用它的一个mixins:
.rotate(degrees);
例子:
.rotate(-90deg);
我有问题,试图在纯CSS -取决于字体,它可以看起来有点垃圾。作为一种替代方法,您可以使用SVG/VML来实现它。有一些库可以帮助它轻松地跨浏览器,例如Raphael和ExtJS。在ExtJS4中,代码如下所示:
var drawComp = Ext.create('Ext.draw.Component', {
renderTo: Ext.getBody(), //or whatever..
height: 100, width: 100 //ditto..
});
var text = Ext.create('Ext.draw.Component', {
type: "text",
text: "The text to draw",
rotate: {
x: 0, y: 0, degrees: 270
},
x: -50, y: 10 //or whatever to fit (you could calculate these)..
});
text.show(true);
这将在IE6+和所有现代浏览器中工作,然而,不幸的是,我认为你至少需要FF3.0。
另一种解决方案是使用大多数浏览器都支持的SVG文本节点。
<svg width="50" height="300">
<text x="28" y="150" transform="rotate(-90, 28, 150)" style="text-anchor:middle; font-size:14px">This text is vertical</text>
</svg>
演示:https://jsfiddle.net/bkymb5kr/
关于SVG文本的更多信息:http://tutorials.jenkov.com/svg/text-element.html
如果CSS写作模式:sideway -lr是你喜欢的,而你恰巧遇到了基于chromium/chrome的浏览器。你可以试试
{
writing-mode: vertical-rl;
transform: rotate(180deg);
}
所以现在所有的浏览器都支持它。
参考:https://bugs.chromium.org/p/chromium/issues/detail?id=680331 c4
我的解决方案,将工作在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*/
}
推荐文章
- 使伸缩项目正确浮动
- 如何取消最大高度?
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何选择在最后一个子元素之前的元素?
- 如何触发自动填充在谷歌Chrome?
- CSS变换,锯齿边缘在铬
- 创建圈div比使用图像更容易的方法?
- 强迫孩子服从父母的弯曲边界在CSS
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在CSS中@apply是什么?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?