HTML、<title> 中的 SVG <img> 鼠标悬停时不显示工具提示
SVG <img> in HTML, <title> tooltip not displayed on mouseover
我有一个 SVG 图像,其中包含用作工具提示的
元素。
当我在 Mozilla 中加载 SVG 时,工具提示显示正确。
但是,当我在 HTML 文档中使用 SVG 时,通过
元素,工具提示不会在鼠标悬停时显示。
是否可以让工具提示正确显示?
HTML是
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SVG in HTML title test</title>
</head>
<body>
<img src="test.svg" />
</body>
</html>
SVG 是
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/SVG/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" viewBox="0 0 100 100">
<title>SVG in HTML test</title>
<g>
<polygon stroke="black" stroke-width="1" fill="#0000ff" points="20,20 40,20 40,40 20,40" />
<title>rectangle</title>
</g>
<g>
<circle stroke="black" stroke-width="1" fill="#ff0000" cx="70" cy="70" r="10" />
<title>circle</title>
</g>
</svg>
您可以尝试使用 object
标签,但这可能不适用于所有浏览器,我认为它只适用于支持 HTML5
:
的浏览器
<object type="image/svg+xml" data="test.svg">Browser doesn't support SVG</object>
或者,我不太喜欢这个,但你也可以尝试使用 iframe
:
<iframe src="test.svg"></iframe>
这也适用于较旧的浏览器...这两种方法都应显示由 title
标记定义的 tooltips
。我用你的进行了快速(成功)测试。
将适当的 ID 添加到 <title>
:
<title id="uniqueTitleID">SVG in HTML title test</title>
在 <svg>
标签上,添加:
aria-labelledby="uniqueTitleID"
(使用标题 ID)
标题应包含在 aria-labelledby 中,因为它比 aria-describedby
具有更好的 screen-reader 支持
我有一个 SVG 图像,其中包含用作工具提示的
但是,当我在 HTML 文档中使用 SVG 时,通过 元素,工具提示不会在鼠标悬停时显示。
是否可以让工具提示正确显示?
HTML是
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SVG in HTML title test</title>
</head>
<body>
<img src="test.svg" />
</body>
</html>
SVG 是
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/SVG/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" viewBox="0 0 100 100">
<title>SVG in HTML test</title>
<g>
<polygon stroke="black" stroke-width="1" fill="#0000ff" points="20,20 40,20 40,40 20,40" />
<title>rectangle</title>
</g>
<g>
<circle stroke="black" stroke-width="1" fill="#ff0000" cx="70" cy="70" r="10" />
<title>circle</title>
</g>
</svg>
您可以尝试使用 object
标签,但这可能不适用于所有浏览器,我认为它只适用于支持 HTML5
:
<object type="image/svg+xml" data="test.svg">Browser doesn't support SVG</object>
或者,我不太喜欢这个,但你也可以尝试使用 iframe
:
<iframe src="test.svg"></iframe>
这也适用于较旧的浏览器...这两种方法都应显示由 title
标记定义的 tooltips
。我用你的进行了快速(成功)测试。
将适当的 ID 添加到 <title>
:
<title id="uniqueTitleID">SVG in HTML title test</title>
在 <svg>
标签上,添加:
aria-labelledby="uniqueTitleID"
(使用标题 ID)
标题应包含在 aria-labelledby 中,因为它比 aria-describedby
具有更好的 screen-reader 支持