2016-01-18 161 views
1
<svg id="mb-one_top" style="position: absolute; top: -215px;" 
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
preserveAspectRatio="xMidYMid" width="600" height="862" viewBox="0 0 600 862"> 

我努力让自己在移动设备上我的SVG较小,所以使用jQuery的我写:覆盖SVG内嵌样式

var width = $(window).width(); 
if (width == 320) { 
    $('#mb-one_top').attr('width', '350'); 
} 

但它不是压倒一切,使我的SVG宽度从600到350,有什么想法?

+0

这一点很容易使用CSS代码,你可能想'宽度<600',而不是'宽度== 320'? – Rafi

回答

1

我认为你可以做到这样

<style> 
    /* styles for mobile browsers smaller than 480px; (iPhone) */ 
    @media (max-width:480px){ 
     #mb-one_top { 
      width : 350px; 
     } 
    } 
</style> 
+0

是的,但是因为我在SVG上设置了宽度。然后,内联样式将始终覆盖通过样式表添加的任何样式 – PourMeSomeCode

+0

尽管我认为这应该可以做到,但是您可以使用重要来覆盖任何样式'width:350px!important'。 –