Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG-based text input field

Has anyone seen any javascript implementation of a text input field besides http://www.carto.net/papers/svg/gui/textbox/ ?

like image 505
Yurii Rashkovskii Avatar asked Nov 14 '10 04:11

Yurii Rashkovskii


People also ask

Can you put text in an SVG?

SVG treats a text element in much the same way that it treats graphical and shape elements. You position text with x and y coordinates and use fill and stroke options to color text the same way you would with a <circle> or <rect> element.

How do I render text in SVG?

try the following code. var svg = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="30px" height="30px" viewBox="0 0 30 30" enable-background="new 0 0 30 30" xml:space="preserve">'+ '<path fill="#156BB1" d="M22.

How do I type in SVG?

The <text> element can be arranged in any number of sub-groups with the <tspan> element. Each <tspan> element can contain different formatting and position. Text on several lines (with the <tspan> element): Several lines: First line.

How do I change the text color in SVG?

Just like you use stroke for the outline color and fill for the inside color of a shape, you can do the same thing for text in SVGs. And the best news is, if you use fill="currentColor" instead of a hard coded color, you can set the SVG text with CSS. Click run code snippet to see an example right in this answer.


1 Answers

There is an interesting SVG node called foreignObject, which allows you to place HTML, flash, etc within your SVG code. Try the following:

<svg width="100%" height="500" xmlns="http://www.w3.org/2000/svg>   <foreignObject x="10" y="10" width="100" height="150">       <div xmlns="http://www.w3.org/1999/xhtml">       <input></input>           </div>   </foreignObject> </svg> 

EDIT: added xmlns so it works for IE.

like image 107
Ricardo Magalhães Cruz Avatar answered Sep 21 '22 13:09

Ricardo Magalhães Cruz