最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - using Raphael's-library for drawing left aligned text - Stack Overflow

programmeradmin2浏览0评论

I am using Raphael's JavaScript library (/) to draw some graphics into my web-application. I tried the following code:

<html>
<head>
    <title></title>
    <script type="text/javascript" src="raphael/raphael.js"></script>
</head>
<body>    
    <script>
        var paper = Raphael(10, 50, 600, 200);            
        paper.text(300, 50, "first very very long line\nshort line").attr(
            {"font-family":"arial", 
            "font-size":"30",
            "text-align":"left"}
            );
    </script>
</body>
</html>

The result is a graphic with two lines of text that are centered. The css font-family and font-size are displayed correct. But the css text-align is ignored. Why?

(tested with Firefox 8.0 and Chrome 15)

I am using Raphael's JavaScript library (http://raphaeljs./) to draw some graphics into my web-application. I tried the following code:

<html>
<head>
    <title></title>
    <script type="text/javascript" src="raphael/raphael.js"></script>
</head>
<body>    
    <script>
        var paper = Raphael(10, 50, 600, 200);            
        paper.text(300, 50, "first very very long line\nshort line").attr(
            {"font-family":"arial", 
            "font-size":"30",
            "text-align":"left"}
            );
    </script>
</body>
</html>

The result is a graphic with two lines of text that are centered. The css font-family and font-size are displayed correct. But the css text-align is ignored. Why?

(tested with Firefox 8.0 and Chrome 15)

Share Improve this question asked Nov 17, 2011 at 11:20 user1027167user1027167 4,4587 gold badges35 silver badges41 bronze badges 1
  • ok I just found the answer: use "text-anchor":"start" instead of "text-align":"left". – user1027167 Commented Nov 17, 2011 at 11:30
Add a ment  | 

2 Answers 2

Reset to default 14

It seems that Raphael doesn't use text-align property. Instead use the text-anchor property, its possible values are start, middle, end or inherit.

In your example use it like this:

paper.text(300, 50, "first very very long line\nshort line").attr({
    "font-family":"arial", 
    "font-size":"30",
    "text-anchor":"start"
});
paper.text(300, 50, "first very very long line\nshort line").attr(
            {"font-family":"arial", 
            "font-size":"30",
            "text-anchor":"start"}
            );
发布评论

评论列表(0)

  1. 暂无评论