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

发布于 2024-07-17 16:15:06 字数 302 浏览 8 评论 0原文

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

替代文本
(来源:sun.com

How can I display vertical text (90 degree rotated) in all browsers?

alt text
(source: sun.com)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

盗梦空间 2024-07-24 16:15:06

该问题与服务器端语言无关。 如果垂直呈现的文本不再是文本而是图像时没有问题,请选择 tharkun提供的解决方案。 否则,在表示层有办法做到这一点。

首先,(目前)有一个仅限 IE 的解决方案,它是 CSS3 标准的一部分。 您可以实时查看

p {
    writing-mode: tb-rl;
}

CSS3 文本模块还指定了一些文本方向属性

其他人使用 SVG 来

The problem is independent from the server side language. If it's not a problem when the vertically rendered text isn't text anymore but an image, choose the solution provided by tharkun. Otherwise, there are ways to do it in the presentation layer.

First, there's (at the moment) an IE-only solution, which is part of the CSS3 standard. You can check it live.

p {
    writing-mode: tb-rl;
}

The CSS3 text module also specify some properties for text orientation.

Other guys do it with SVG.

绅刃 2024-07-24 16:15:06

我不认为你可以用 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);

I don't think you can rotate text with PHP/HTML/CSS. But you can create an image with GD containing vertical text.

Example:

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);
计㈡愣 2024-07-24 16:15:06
function verticletext($string)
    {
       $tlen = strlen($string);
       for($i=0;$i<$tlen;$i++)
       {
            $vtext .= substr($string,$i,1)."<br />";   
       }
       return $vtext;
    }

你去那里没有回声

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

there you go no echo

淑女气质 2024-07-24 16:15:06

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

CSS:

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

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

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

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

Text rotation is also possible with other browsers.

CSS:

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

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

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

/*IE*/
writing-mode: tb-rl;
filter: flipV flipH;
玩物 2024-07-24 16:15:06

如果表标题行太长,我使用下面的函数。 它非常有用,因为它易于使用、速度快,而且您无需计算文本高度和文本高度。 宽度。 那些 css 花招根本不起作用。

#######################################################
# 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'>";

}

I use the function below if table header rows are too long. It's quite useful because it's easy to use, fast and you don't have to calculate text height & width. Those css-gimmicks just don't work.

#######################################################
# 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'>";

}

那一片橙海, 2024-07-24 16:15:06

此帖子建议您可以将文本写入图像,然后旋转图像。

IE 似乎可以,但其他浏览器不行,所以这可能是 IE6 的小胜利之一 =)

This thread suggests that you can write text to an image and then rotate the image.

It appears to be possible with IE but not with other browsers so it might be one of those little win for IE6 =)

假面具 2024-07-24 16:15:06

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

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

As far as I know it's not possible to get vertical text with CSS, so that means that the rotated text has to be in an image. It's very straightforward to generate with PHP's' libgd interface to output an image file.

Note however that this means using one script to produce the image, and another to produce the surrounding web page. You can't generally (inline data: URI's notwithstanding) have one script produce more than one page component.

那些过往 2024-07-24 16:15:06

使用拉斐尔js
它也适用于 IE 6

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

Use raphaeljs
It works on IE 6 also

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

瞄了个咪的 2024-07-24 16:15:06
   function verticletext($string)
    {
       $tlen = strlen($string);
       for($i=0;$i<$tlen;$i++)
       {
            echo substr($string,$i,1)."<br />";   
       }
    }
   function verticletext($string)
    {
       $tlen = strlen($string);
       for($i=0;$i<$tlen;$i++)
       {
            echo substr($string,$i,1)."<br />";   
       }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文