如何在所有浏览器中显示垂直文本(旋转90度)?

时间:2009-04-21 07:03:22

标签: browser cross-browser text-rotating

如何在所有浏览器中显示垂直文本(旋转90度)?

alt text
(来源:sun.com

10 个答案:

答案 0 :(得分:7)

问题与服务器端语言无关。如果垂直渲染的文本不再是文本而不是图像时不是问题,请选择solution provided by tharkun。否则,有方法可以在表示层中执行此操作。

首先,(目前)还有一个仅限IE的解决方案,即part of the CSS3 standard。你可以check it live

p {
    writing-mode: tb-rl;
}

CSS3 text module还指定了一些properties for text orientation

其他人这样做with SVG

答案 1 :(得分:5)

我认为您不能使用PHP / HTML / CSS旋转文本。但您可以使用包含垂直文本的GD创建图像。

示例:

header ("Content-type: image/png"); 

// imagecreate (x width, y width)
$img_handle = @imagecreatetruecolor (15, 220) or die ("Cannot Create image"); 

// ImageColorAllocate (image, red, green, blue)
$back_color = ImageColorAllocate ($img_handle, 0, 0, 0); 
$txt_color = ImageColorAllocate ($img_handle, 255, 255, 255); 
ImageStringUp ($img_handle, 2, 1, 215, $_GET['text'], $txt_color); 
ImagePng ($img_handle); 
ImageDestroy($img_handle);

答案 2 :(得分:1)

function verticletext($string)
    {
       $tlen = strlen($string);
       for($i=0;$i<$tlen;$i++)
       {
            $vtext .= substr($string,$i,1)."<br />";   
       }
       return $vtext;
    }

你没有回声

答案 3 :(得分:1)

其他浏览器也可以旋转文本。

CSS:

/*Safari*/
-webkit-transform: rotate(-90deg);

/*Firefox*/
-moz-transform: rotate(-90deg);

/*Opera*/
-o-transform: rotate(-90deg);

/*IE*/
writing-mode: tb-rl;
filter: flipV flipH;

答案 4 :(得分:1)

如果表标题行太长,我会使用下面的函数。它非常有用,因为它易于使用,速度快,而且您无需计算文本高度和高度。宽度。那些css-gimmicks就是行不通。

#######################################################
# convert text to image and embed it to html
# uses /tmp as a cache to make it faster
# usage: print imagetext("Hello my friend");
# Created by Ville Jungman, GPL-licenced, donated by www.varuste.net

function imagetext($text,$size = 10,$color = array(253,128,46)){
  $dir = "/tmp/tekstit";
  $filename = "$dir/" . base64_encode($text);
  if(!file_exists($filename)){
     $font = "/usr/share/fonts/truetype/freefont/FreeSans.ttf";
     $box = imagettfbbox($size,90,$font,$text);
     $w = -$box[4] - 1;
     $h = -$box[3];
     $im = imagecreatetruecolor($w,$h);
     $white = imagecolorallocate($im,$color[1],$color[2],$color[3]);
     $black = imagecolorallocate($im, 0x00, 0x00, 0x00);
     imagecolortransparent($im,$white);
     imagefilledrectangle($im, 0, 0, $size, 99, $white);
     imagettftext($im,$size,90,$size,$h,$black,$font,$text);
     @mkdir($dir);
     imagepng($im,$filename);
     imagedestroy($im);
  }
  $data = base64_encode(file_get_contents($filename));
  return "<img src='data:image/png;base64,$data'>";

}

答案 5 :(得分:0)

This thread表示您可以将文字写入图像,然后旋转图像。

似乎可以使用IE而不是其他浏览器,因此它可能是IE6的小胜利之一=)

答案 6 :(得分:0)

imagettftext这个诀窍。

答案 7 :(得分:0)

据我所知,用CSS获取垂直文本是不可能的,这意味着旋转的文本必须在图像中。使用PHP的'libgd接口生成输出图像文件非常简单。

但请注意,这意味着使用一个脚本生成图像,另一个脚本生成周围的网页。您通常不能(内联数据:URI尽管如此)有一个脚本生成多个页面组件。

答案 8 :(得分:0)

使用raphaeljs 它也适用于IE 6

http://raphaeljs.com/text-rotation.html

答案 9 :(得分:-3)

   function verticletext($string)
    {
       $tlen = strlen($string);
       for($i=0;$i<$tlen;$i++)
       {
            echo substr($string,$i,1)."<br />";   
       }
    }
相关问题