By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

solution to display text rotated 90 vertically in firefox css

P: 2
I have been searching for hours to find a solution to display text rotated at 90 degrees in firefox, and could not find one. css3 and IE has the css command "writing-mode: tb-rl;" but this does not work in firefox. i came to conclusion that SVG is the solution. I have been playing with SVG for few hours now and it is brilliant, you can do graphics and animation like flash but text and javascript based!. anyway check this out, this is one solution to do it in svg and it works.

put this in html document

Expand|Select|Wrap|Line Numbers
  1. <embed class="svgex" src="../thefile.svg" type="image/svg+xml" frameborder="no" width="30" height="60" />
and here is the svg file

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  3. <svg version="1.1"   xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  4. <script type="text/javascript">
  5. <![CDATA[
  6. //this will create htmljavascriptfunctionname in html document and link it to changeText
  7. top.htmljavascriptfunctionname = changeText;
  8.  
  9. function changeText(txt){
  10.    targetText=document.getElementById("thetext");
  11.    var newText = document.createTextNode(txt);
  12.    targetText.replaceChild(newText,targetText.childNodes[0]);
  13. }
  14. // ]]>
  15. </script>
  16. <text id="thetext" transform="rotate(90,4,4)" font-size="10" x="4" y="4" font-family="Verdana">this text is rotated </text> 
  17.  
  18. </svg>
This idea could be developed further to create the svg object in the html document dom, dynamically with javascript and therefore with no external svj file or an embed object being required. if this woudl be useful to you let me know
Oct 11 '07 #1
Share this Question
Share on Google+
5 Replies


drhowarddrfine
Expert 5K+
P: 7,435
SVG is great and it should be used everywhere but it only works in modern browsers and not IE6/7.
Oct 11 '07 #2

P: 2
It's been a couple years since this thread was started, so I hope I'm not too late. Please reply if you can.

I can get this to work--sort of. Following the instructions, I get the text line saying "This line is rotated" turned 90 degrees. Terrific. But the CDATA section in the svg document contains a javascript function with a parameter: txt, which to me suggests that I should be able to call that function from within the HTML document (in javascript, of course), include a different line of text as the argument, and have that new text rotated. But I can't get it to work. I can't call the function from the HTML document: I get an "Undefined variable" error. And since the .svg file is embedded, I can't figure out how to address it (ie, with something like embed.document.getElementById() or embed.changeText(new text). I've tried moving the changeText() function to the HTML document, but again, I can't then get the internal function statements to point to the .svg file.

I'm reasonably competent with HTML and javascript, but I've never worked with .svg before. I read up on it a bit, but the problem doesn't seem to be with .svg per se; it's with linking the .svg file to the HTML document.

This idea could be developed further to create the svg object in the html document dom, dynamically with javascript and therefore with no external svj file or an embed object being required. if this woudl be useful to you let me know
Maybe this is the answer. It sounds like it should be. Has anyone worked out how to do it?

FYI: I'm using Opera 9.64, not Firefox. But since I get the correct rotation of the original line, I can't imagine the problem is with the browser.
Aug 14 '09 #3

P: 1
Hi,

At the beginning of the CDATA section, see this assignment:

top.htmljavascriptfunctionname = changeText;

This "binds" the function changeText (which is in the context of the SVG object), to a function (called htmljavascriptfunctionname which you need to call ) in the containing HTML document.

So in your HTML page, call the function htmljavascriptfunctionname() whenever you want to change the text. e.g.

htmljavascriptfunctionname("my next text");

This works on FF 3.5, I assume it will on Opera.

Hope this helps,
Asaf.
Aug 26 '09 #4

P: 2
Thanks for the tip, AsafAmit. I'll give it a try.

I finally did figure out another way to do it. First move the changeText function to the HTML document. From within that HTML doc, open the .svg doc with javascript, assigning a variable to the window.open statement:

Expand|Select|Wrap|Line Numbers
  1. turnTextPage = window.open( "savedDocument.svg","","params, etc.");
Then add the variable name to the changeText function:

Expand|Select|Wrap|Line Numbers
  1. function changeText( lineID, text ){
  2.     targetText = turnTextPage.document.getElementById( lineID ) ;
  3.     var newText = turnTextPage.document.createTextNode( text ) ;
  4.     targetText.replaceChild( newText, targetText.childNodes[0] );
  5. }
SInce the function is now in the HTML doc, you can call it the normal way, and the text lines will be transferred to the .svg doc.
Aug 27 '09 #5

P: 1
I tried to replace flash SWF object with sgv object. The followings are my code. The result is as the attached. It's not right.
I am more a server side person (JSF). Not 1 Javascript person Need some instruction to get this work. Thanks[IMG]file:///home/sling/dashboard.png[/IMG]
The image might not work. Basically, it display once out of place (in top of screen. All vertical line with undefined wording.
Expand|Select|Wrap|Line Numbers
  1. <t:dataList id="profileList" var="profile" value="#{Dashboard2Bean.profileList}" rowIndexVar="row">
  2.                     <td rowspan="2">                        
  3.                         <div id="verticalTextDiv">
  4.                          <script type="text/javascript">
  5.                              var output = '<h:outputText value="#{profile.vendorAbbrvName}" /> - <h:outputText value="#{profile.name}" />';
  6.                              document.writeln(displayVerticalText(output));
  7.                         </script>
  8.                         </div>
  9.                     </td>
  10.                 </t:dataList>
  11.  
Nov 11 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.