PDA

View Full Version : making text diagonal


boggly
07-27-2002, 08:48 AM
Hello!

I'm working on a site in which the layout calls for diagonal links in the menu. The menus is in a table with simple text inside of the cells. My question is wheather there's any way to get the text to slant from left to right going up? I've tried fiddling with some of the CSS rules without much success.

TIA,
boggly

COBOLdinosaur
07-27-2002, 04:45 PM
You will have to do it with graphics. There is no CSS property that is going to do it except you could put each character in the string in a seperate div and then absolutely position each one.

That would be a lot of coding for not much benefit, and it would be a nightmare to get it cross browser and cross-resolution compatible.

boggly
07-27-2002, 05:55 PM
I find that kind of odd that CSS can't do something like that. I didn't really want to take the high-bandwidth graphics route, but if that's the only way then I guess I don't have much of a choice.

Regards,
boggly

iceman
07-27-2002, 06:31 PM
Someone posted this on old forum, but sorry don't remember who or when. Anyway it's cool and maybe it'll help you.

<html>
<head>
<style>
.rel { position: relative;font-family:arial;font-weight:bold;color:blue; }
</style>
<script>
var ref = 0;
function angleText (what, dir, angle, space) {
angle = angle || 45;
angle = Math.PI/180 * angle;
space = space || 10;
degY = space * Math.tan(angle);
var txt = '';
txt += '<DIV ID="td' + ref + '"' + ' class="rel"' + '>';
if (dir) {
for (var r = 0; r < what.length; r++) {
txt += '<SPAN ID="td' + ref + r + '" class="rel" STYLE="left: ' + (r * space) + 'px; top: ' + (r * degY) + 'px;">';
txt += what.charAt(r);
txt += '</SPAN>';
}
}
else {
for (var r = 0; r < what.length; r++) {
txt += '<SPAN ID="td' + ref + r + '" class="rel" STYLE="left: ' + (r * space) + 'px; top: ' + ((what.length - r) * degY) + 'px;">';
txt += what.charAt(r);
txt += '</SPAN>';
}
}
txt += '<\/DIV>';
ref ++;
document.write(txt);
}
</script>

</head>
<body bgcolor=#ffffbo>

<script>
angleText('DHTML is really cool! First Line', true, 225, 5);
angleText('DHTML is really cool! Second Line', false, 225, 5);
</script>

<div id="test in div" style="position:absolute;top:200;left:100;background-color:yellow;width:400;height:150;">this one is inside a div<script>
angleText('DHTML is really cool! First Line', true, 225, 5);
angleText('DHTML is really cool! Second Line', false, 225, 5);
</script></div>

<br><br><br><br><br><br><br><br><br><br><br><br>

Just change the parameters in this order: the text; direction (true for normal, false for invert); the angle; and the line spacing.
</body>
</html>

jkd
07-27-2002, 06:55 PM
Using SVG and the <foreignObject> tag, you can apply an SVGTransform of a rotation to any XHTML.

IE also some proprietary filter property which let's you rotate content.

MCookie
07-27-2002, 07:36 PM
Maybe this link will help you too:
http://www.meyerweb.com/eric/css/edge/curvelicious/demo.html

boggly
07-27-2002, 11:03 PM
Thanks for all the suggestions everyone. I'll be sure to check them out. In regards to SVG though, do any of the major browsers support that format yet?

Regards,
boggly

boggly
07-28-2002, 12:06 AM
Yes, that script was almost exactly what I wanted iceman. The only complaint I have with it is that I wanted the letters to line up in a diagonal manner but going up straight--if that makes any sense. My math isn't that great so I don't know how to get the script to do that. Otherwise, I'll just have to try and tweak the parameters to try and get it as close as I can.

Thanks again,
boggly