【发布时间】:2015-07-22 04:31:26
【问题描述】:
我整天都在致力于使 SVG 具有响应性并阅读各种文章,并测试不同类型的代码,即使在堆栈溢出时也是如此。 不幸的是,我没有成功让我的 svg 基于容器 div 展开,就像我通常在定义 max-width:100% 时对图像所做的那样
我使用 SVG 堆栈作为技术: http://simurai.com/blog/2012/04/02/svg-stacks/ 他的代码示例:http://jsfiddle.net/simurai/7GCGr/
我注意到,在 svg 达到一定尺寸后,它不再扩展,即使我将其 100% 作为宽度,他的最大尺寸也变为 150px。 如果我通过插入宽度和高度尺寸来强制它变大,但这不是我想要的。我希望它总是根据容器的宽度调整大小,甚至变得非常巨大而没有任何大小限制。
在 svg 中,高度和宽度被删除。
我的代码:
/* RESET - http://meyerweb.com/eric/tools/css/reset/ */
html, body, applet, object, iframe, svg, h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, figure{
margin:0; padding:0; border:0; font-size:100%; font-weight:inherit; font-style:inherit;
font-family:inherit; text-decoration:inherit; text-align:left; background:transparent;
}
header, footer, figure, details, hgroup, section, article, nav, aside{display:block;}
img, object, audio, video, svg{width:100%;}
.vector{display:block; width:100%; height:auto;}
.vector embed{border:1px solid #f00; width:100%;}*/
.box{border:1px solid #f00; width:700px;}
<div class="box">
<object class="vector">
<embed src="http://life-is-simple.net/sprite.svg#winner-cup" />
</object>
<img class="vector" src="http://life-is-simple.net/sprite.svg#winner-cup">
<img class="vector" src="http://life-is-simple.net/sprite.svg#lottery-ticket">
<img class="vector" src="http://life-is-simple.net/sprite.svg#monitor-number">
<img class="vector" src="http://life-is-simple.net/sprite.svg#emblem">
</div>
我真的很感激一些帮助,我不知道再测试什么才能让它工作,特别是当我看到插入的简单包含 svg 时,它们确实 100% 运行,我正在尝试使用和技术,但我没有看到任何区别(只有 IE 可以扩展 svg,但 firefox 和 chrome 不会)
【问题讨论】:
-
embed在大多数浏览器中不支持是吗? - sitepoint.com/add-svg-to-web-page -
我正在阅读这篇文章:smashingmagazine.com/2014/11/03/…,其中谈到了嵌入(但我认为我忽略了几点,我只是测试一下在不同实现中使用 svg 的效果) ,但我认为这个解决方案是更好的选择stackoverflow.com/questions/4476526/…
标签: css svg responsive-design