admin管理员组文章数量:1293902
I'm trying to have a block of text in a div fill a downward triangle shape. Is there any way to achieve this with either CSS or Javascript?
This is for a site in which users can dynamically insert text. I'm trying to avoid the alternative method, which is to have them insert text line by line with a limit on each line.
I'm trying to have a block of text in a div fill a downward triangle shape. Is there any way to achieve this with either CSS or Javascript?
This is for a site in which users can dynamically insert text. I'm trying to avoid the alternative method, which is to have them insert text line by line with a limit on each line.
Share asked Sep 12, 2011 at 18:05 theNewmantheNewman 1171 gold badge3 silver badges10 bronze badges 1- 1 Check out this page – Eric Commented Sep 12, 2011 at 18:50
4 Answers
Reset to default 5I don't know of any simple way to do what you are asking for. The best thing I can think of would be to use something like the CSS text wrapper, which can fit your text to any shape. I haven't used it myself so I don't know what problems you will run into.
Your question is very similar to this one.
I know of no CSS way, but you can do it with JavaScript. The idea is to find where each line of text breaks and wrap the remaining text in a new child div. You have to use text ranges to acplish it.
See this demo: http://jsfiddle/gilly3/CmguZ/7/
You could wrap each line of your text with a <span>
and use margins to recieve the wanted affect and if you want the shape to have a color use photoshop to create a triangle with the desired color and put it on the background.
you can try playing with CSS border slopes, but I don't think it fits your needs entirely, because it's a bit plicated and you have to wrap the text manually. there are some good examples of this method here, but it is for simple shapes basically, not for text containers.
本文标签: javascriptAny way to have text in div fill a triangle shapeStack Overflow
版权声明:本文标题:javascript - Any way to have text in div fill a triangle shape? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741590230a2387079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论