2015-07-02 74 views
0

我試圖爲一個img SVG添加一個標題。 標題在圖片的底部。 的代碼是這樣:爲SVG <image>創建標題

<svg> 
    <image> 
</svg> 

如何實現這不使用內? 而且我也想基於D3.js,如果可能的話。

謝謝。

+0

作中,你希望它這樣,當鼠標懸停在它,它給翻轉標題? 'svg title =「foobar」或'image =「foobar」'是否取得了任何成功或顯着的行爲? – Goose

+0

你的意思是''? –

+0

我的意思是''或''。我的錯。你有沒有嘗試過,如果是的話,你有什麼行爲? – Goose

回答

1

在SVG元素中,不使用title屬性。您必須使用一個<title>元素,該元素放入其應用的元素中。

<svg> 
 
    <image xlink:href="http://lorempixel.com/300/150/" width="300" height="150"> 
 
     <title>foobar</title> 
 
    </image> 
 
</svg>

+0

還有一個問題。我可以通過CSS更改的形狀嗎?我試過了,但沒有奏效。 – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">不,你不能。它就像HTML屬性一樣。 – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1038284119" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">0<i class="fa fa-thumbs-up"></i></span> </div> <div class="post-offset"> <div class="answer fmt"> <p>您可以簡單地在圖片下方放一段文字。把文本y位置=圖像高度+有點填充。或者,您可以將y位置放置在比圖像高度稍低的位置,並且它會落在圖像頂部。</p> <pre><code class="prettyprint-override"><?xml version="1.0" encoding="utf-8"?> <!-- from this website http://tutorials.jenkov.com/svg/svg-and-css.html --> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <image x="0" y="0" height="100" width="100" id="HVACEast" preserveAspectRatio="none" xlink:href="https://some.site.com/image.png" opacity="0.4" style="pointer-events: none"/> <text stroke-width=".05" fill="#66CCB2" x="5" y="105" font-family="serif" font-size="5pt">IMAGE TITLE</text> </svg> </code></pre> <p>或者使用TSPAN的文本。</p> <pre><code class="prettyprint-override"><text> <tspan x="5" y="105" font-size="5pt" fill="yellow">Image</tspan> <tspan x="5" y="108" font-size="5pt" stroke="blue">Title</tspan> </text> </code></pre> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/31187956">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2015-07-02 14:54:33</span> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/5073840/">MatthewD</a></span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> <!-- comments --> <div class="comments"> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">這確實是一種方法。但<text>無法輕鬆包裝這個詞,對吧?你有另一種方式或解決方法嗎? – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">SVG 1.1沒有文字換行。您可以使用tspan爲您提供包裝風格的文本。這是一個更多的工作。請參閱修改原始答案。 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/5073840/">MatthewD</a></span> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="clearfix"> </div> <div class="relative-box"> <div class="relative">相關問題</div> <ul class="relative_list"> <li> 1. <a href="http://hk.uwenku.com/question/p-uxdegerh-bno.html" target="_blank" title="創建標題爲drawerlayout?"> 創建標題爲drawerlayout? </a> </li> <li> 2. <a href="http://hk.uwenku.com/question/p-xpfpkuyp-bbz.html" target="_blank" title="爲Google地圖標記創建多色svg圖標"> 爲Google地圖標記創建多色svg圖標 </a> </li> <li> 3. <a href="http://hk.uwenku.com/question/p-xhrvhomw-hc.html" target="_blank" title="從svg座標創建Bo​​x2dWeb障礙"> 從svg座標創建Bo​​x2dWeb障礙 </a> </li> <li> 4. <a href="http://hk.uwenku.com/question/p-sxmknhqx-nc.html" target="_blank" title="從流明中的.svg創建圖標"> 從流明中的.svg創建圖標 </a> </li> <li> 5. <a href="http://hk.uwenku.com/question/p-roouxqac-bgs.html" target="_blank" title="使用JavaScript創建SVG標記"> 使用JavaScript創建SVG標記 </a> </li> <li> 6. <a href="http://hk.uwenku.com/question/p-dmzkamrl-bhw.html" target="_blank" title="SVG標題延遲"> SVG標題延遲 </a> </li> <li> 7. <a href="http://hk.uwenku.com/question/p-vphioile-zc.html" target="_blank" title="用Raphael創建SVG"> 用Raphael創建SVG </a> </li> <li> 8. <a href="http://hk.uwenku.com/question/p-zrkojidi-d.html" target="_blank" title="創建SVG三角"> 創建SVG三角 </a> </li> <li> 9. <a href="http://hk.uwenku.com/question/p-gloegbpe-od.html" target="_blank" title="無法創建svg"> 無法創建svg </a> </li> <li> 10. <a href="http://hk.uwenku.com/question/p-hrfcaygd-bhs.html" target="_blank" title="svg創建圈子"> svg創建圈子 </a> </li> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6208739752673518" data-ad-slot="4606349252"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <li> 11. <a href="http://hk.uwenku.com/question/p-eavqgvef-qm.html" target="_blank" title="如何爲perl創建標題?"> 如何爲perl創建標題? </a> </li> <li> 12. <a href="http://hk.uwenku.com/question/p-xmqitcnz-bo.html" target="_blank" title="爲僅標題庫創建塊"> 爲僅標題庫創建塊 </a> </li> <li> 13. <a href="http://hk.uwenku.com/question/p-zxcvsauy-bmn.html" target="_blank" title="爲CSV文件創建標題"> 爲CSV文件創建標題 </a> </li> <li> 14. <a href="http://hk.uwenku.com/question/p-raojwwba-x.html" target="_blank" title="matlab爲每個boxplot創建標題"> matlab爲每個boxplot創建標題 </a> </li> <li> 15. <a href="http://hk.uwenku.com/question/p-arnqoitt-gc.html" target="_blank" title="如何爲unicode標題創建unicode slu??"> 如何爲unicode標題創建unicode slu?? </a> </li> <li> 16. <a href="http://hk.uwenku.com/question/p-culrepig-zg.html" target="_blank" title="爲JTable創建多行標題"> 爲JTable創建多行標題 </a> </li> <li> 17. <a href="http://hk.uwenku.com/question/p-bqtwypaz-sq.html" target="_blank" title="爲彈出窗口創建標題"> 爲彈出窗口創建標題 </a> </li> <li> 18. <a href="http://hk.uwenku.com/question/p-mledotux-bky.html" target="_blank" title="爲BaseAdapter創建對象標題的getFilter?"> 爲BaseAdapter創建對象標題的getFilter? </a> </li> <li> 19. <a href="http://hk.uwenku.com/question/p-xlzimudv-rb.html" target="_blank" title="我如何使用帶有<svg>和<use>標籤的SVG圖標"> 我如何使用帶有<svg>和<use>標籤的SVG圖標 </a> </li> <li> 20. <a href="http://hk.uwenku.com/question/p-konvqgmf-bgv.html" target="_blank" title="如何爲svg路徑創建動畫?"> 如何爲svg路徑創建動畫? </a> </li> <li> 21. <a href="http://hk.uwenku.com/question/p-gnjanlfs-eh.html" target="_blank" title="爲什麼我的SVG不被創建?"> 爲什麼我的SVG不被創建? </a> </li> <li> 22. <a href="http://hk.uwenku.com/question/p-bynxzttn-ha.html" target="_blank" title="無法創建SVG線,但創建SVG圈工作正常"> 無法創建SVG線,但創建SVG圈工作正常 </a> </li> <li> 23. <a href="http://hk.uwenku.com/question/p-phpjmsky-bhp.html" target="_blank" title="創建一個帶標題的標題邊框作爲JCheckBox"> 創建一個帶標題的標題邊框作爲JCheckBox </a> </li> <li> 24. <a href="http://hk.uwenku.com/question/p-hubopqyz-bah.html" target="_blank" title="創建不透明標題"> 創建不透明標題 </a> </li> <li> 25. <a href="http://hk.uwenku.com/question/p-ruzwuquk-bcv.html" target="_blank" title="的Javadoc將創建標題"> 的Javadoc將創建標題 </a> </li> <li> 26. <a href="http://hk.uwenku.com/question/p-gztywifd-x.html" target="_blank" title="創建標準主題"> 創建標準主題 </a> </li> <li> 27. <a href="http://hk.uwenku.com/question/p-kejsiqjg-wa.html" target="_blank" title="自定義「創建<內容類型>」的標題"> 自定義「創建<內容類型>」的標題 </a> </li> <li> 28. <a href="http://hk.uwenku.com/question/p-asnmqxzd-bnq.html" target="_blank" title="標題一個SVG與<text>元素?"> 標題一個SVG與<text>元素? </a> </li> <li> 29. <a href="http://hk.uwenku.com/question/p-ebpqbtlb-yu.html" target="_blank" title="創建標題頁活動"> 創建標題頁活動 </a> </li> <li> 30. <a href="http://hk.uwenku.com/question/p-twpfojqh-bbh.html" target="_blank" title="CSS問題,創建標籤"> CSS問題,創建標籤 </a> </li> </ul> </div> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1575177025"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img.uwenku.com/uwenku/script/side.js?t=1644592048261"></script> <script type="text/javascript" src="http://img.uwenku.com/uwenku/plugin/highlight/highlight.pack.js"></script> <link href="http://img.uwenku.com/uwenku/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="5415218910" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="row sidebar panel panel-default"> <div class="panel-heading font-bold"> 最新問題 </div> <div class="m-b-sm m-t-sm clearfix"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-nektflpk-bbo.html" target="_blank" title="字體面在IE或邊緣"> 字體面在IE或邊緣 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-yrrswvsk-xg.html" target="_blank" title="訪問變量和模塊的方法,在多模塊程序"> 訪問變量和模塊的方法,在多模塊程序 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-cwqvptsm-yy.html" target="_blank" title="如何在C#中使用Web HDFS REST API追加文件?"> 如何在C#中使用Web HDFS REST API追加文件? </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-adtrrjqe-zp.html" target="_blank" title="Google Drive API v3 .NET:如何讓用戶直接從谷歌驅動器下載文件而不是從服務器下載文件?"> Google Drive API v3 .NET:如何讓用戶直接從谷歌驅動器下載文件而不是從服務器下載文件? </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-uzqoevxw-xw.html" target="_blank" title="行表中的Javafx表"> 行表中的Javafx表 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-tjaeqkvp-xp.html" target="_blank" title="最佳/最有效的方式爲nvarchar(最大)轉換到爲nvarchar(30)"> 最佳/最有效的方式爲nvarchar(最大)轉換到爲nvarchar(30) </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-xspueoga-ym.html" target="_blank" title="無法加入Mapbox SDK來的build.gradle"> 無法加入Mapbox SDK來的build.gradle </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-motyakjv-yc.html" target="_blank" title="Ramdajs keyBy相當於lodash"> Ramdajs keyBy相當於lodash </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-pkzicjfz-wn.html" target="_blank" title="PHP無法發送UTF-8的消息"> PHP無法發送UTF-8的消息 </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-mpazrjuc-wd.html" target="_blank" title="從表構建樹結構?"> 從表構建樹結構? </a> </li> </ul> </div> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> 相關問題</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-uxdegerh-bno.html" target="_blank" title="創建標題爲drawerlayout?"> 創建標題爲drawerlayout? </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-xpfpkuyp-bbz.html" target="_blank" title="爲Google地圖標記創建多色svg圖標"> 爲Google地圖標記創建多色svg圖標 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-xhrvhomw-hc.html" target="_blank" title="從svg座標創建Bo​​x2dWeb障礙"> 從svg座標創建Bo​​x2dWeb障礙 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-sxmknhqx-nc.html" target="_blank" title="從流明中的.svg創建圖標"> 從流明中的.svg創建圖標 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-roouxqac-bgs.html" target="_blank" title="使用JavaScript創建SVG標記"> 使用JavaScript創建SVG標記 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-dmzkamrl-bhw.html" target="_blank" title="SVG標題延遲"> SVG標題延遲 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-vphioile-zc.html" target="_blank" title="用Raphael創建SVG"> 用Raphael創建SVG </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-zrkojidi-d.html" target="_blank" title="創建SVG三角"> 創建SVG三角 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-gloegbpe-od.html" target="_blank" title="無法創建svg"> 無法創建svg </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-hrfcaygd-bhs.html" target="_blank" title="svg創建圈子"> svg創建圈子 </a> </li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://hk.uwenku.com/contact">聯系我們</a></li> <li>© 2020 HK.UWENKU.COM</li> <li><a target="_blank" href="https://beian.miit.gov.cn/">沪ICP备13005482号-4</a></li> <li><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1280101193&web_id=1280101193"></script></li> <li><a href="http://www.uwenku.com/" target="_blank" title="优文库">简体中文</a></li> <li><a href="http://hk.uwenku.com/" target="_blank" title="優文庫">繁體中文</a></li> <li><a href="http://ru.uwenku.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.uwenku.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.uwenku.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.uwenku.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.uwenku.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.uwenku.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.uwenku.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.uwenku.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.uwenku.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.uwenku.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.uwenku.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f78a970f17b19a79fc477a3378096f29"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>