html - 使用 Bootstrap 的响应式内联 SVG

标签 html twitter-bootstrap svg responsive

如何使用 Bootstrap 使内联 svg 图标响应?这是一个示例代码:

<svg id="mute-audio" xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewbox="-10 -10 68 68">
    <circle cx="24" cy="24" r="34">
        <title>Mute Audio</title>
    </circle>
    <path class="on" transform="scale(0.6), translate(17,18)" d="M38 22h-3.4c0 1.49-.31 2.87-.87 4.1l2.46 2.46C37.33 26.61 38 24.38 38 22zm-8.03.33c0-.11.03-.22.03-.33V10c0-3.32-2.69-6-6-6s-6 2.68-6 6v.37l11.97 11.96zM8.55 6L6 8.55l12.02 12.02v1.44c0 3.31 2.67 6 5.98 6 .45 0 .88-.06 1.3-.15l3.32 3.32c-1.43.66-3 1.03-4.62 1.03-5.52 0-10.6-4.2-10.6-10.2H10c0 6.83 5.44 12.47 12 13.44V42h4v-6.56c1.81-.27 3.53-.9 5.08-1.81L39.45 42 42 39.46 8.55 6z" fill="white"/>

    <path class="off" transform="scale(0.6), translate(17,18)"  d="M24 28c3.31 0 5.98-2.69 5.98-6L30 10c0-3.32-2.68-6-6-6-3.31 0-6 2.68-6 6v12c0 3.31 2.69 6 6 6zm10.6-6c0 6-5.07 10.2-10.6 10.2-5.52 0-10.6-4.2-10.6-10.2H10c0 6.83 5.44 12.47 12 13.44V42h4v-6.56c6.56-.97 12-6.61 12-13.44h-3.4z"  fill="white"/>
</svg>

我尝试了不同的:

  1. class="img-responsive"in svg

  2. class="embed-responsive-item"在 容器div

到目前为止运气不好。如何实现?

最佳答案

viewbox 应该是 viewBox。 SVG 属性区分大小写。

您还需要删除 widthheight 值 - 或者将它们更改为 "100%"

<svg id="mute-audio" xmlns="http://www.w3.org/2000/svg"
     width="100%" height="100%" viewBox="-10 -10 68 68">
    <circle cx="24" cy="24" r="34">
        <title>Mute Audio</title>
    </circle>
    <path class="on" transform="scale(0.6), translate(17,18)" d="M38 22h-3.4c0 1.49-.31 2.87-.87 4.1l2.46 2.46C37.33 26.61 38 24.38 38 22zm-8.03.33c0-.11.03-.22.03-.33V10c0-3.32-2.69-6-6-6s-6 2.68-6 6v.37l11.97 11.96zM8.55 6L6 8.55l12.02 12.02v1.44c0 3.31 2.67 6 5.98 6 .45 0 .88-.06 1.3-.15l3.32 3.32c-1.43.66-3 1.03-4.62 1.03-5.52 0-10.6-4.2-10.6-10.2H10c0 6.83 5.44 12.47 12 13.44V42h4v-6.56c1.81-.27 3.53-.9 5.08-1.81L39.45 42 42 39.46 8.55 6z" fill="white"/>

    <path class="off" transform="scale(0.6), translate(17,18)"  d="M24 28c3.31 0 5.98-2.69 5.98-6L30 10c0-3.32-2.68-6-6-6-3.31 0-6 2.68-6 6v12c0 3.31 2.69 6 6 6zm10.6-6c0 6-5.07 10.2-10.6 10.2-5.52 0-10.6-4.2-10.6-10.2H10c0 6.83 5.44 12.47 12 13.44V42h4v-6.56c6.56-.97 12-6.61 12-13.44h-3.4z"  fill="white"/>
</svg>

关于html - 使用 Bootstrap 的响应式内联 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38580538/

相关文章:

javascript - 如何获取SVG折线元素的高度和宽度?

html - HTML视频标签可用于grails吗?

html - 推特 Bootstrap : Input fields taking up too much space when page size is reduced

css - Rails 样式在 link_to 嵌套表单中丢失

html - 无法将登录按钮放在导航栏的右侧

css - SVG 背景图像在 Safari 中无法正确缩放

javascript - 为什么 jQuery 的 show() 和 hide() 方法会触发淡入淡出?

javascript - 卸载前无法正常工作?

css - 获取 Bootstrap css 文件

html - 有没有办法让 svg 元素可以在 html 页面上突出显示?