开发者

Fit <svg> to the size of <object> container

开发者 https://www.devze.com 2023-02-05 18:38 出处:网络
I have this markup: #widget1 { height:100px; width:200px; } <div class=\"widget\" id=\"widget1\"> <object data=\"foo.开发者_高级运维svg\" type=\"image/svg+xml\" />

I have this markup:

#widget1 {
    height:100px;
    width:200px;
}

<div class="widget" id="widget1">
    <object data="foo.开发者_高级运维svg" type="image/svg+xml" />
</div>

I managed to make the <object> element fill up the outer <div>, but the inner foo.svg file has its own ideas how big it is. I need foo.svg (which consists of an <svg> element, of course) to be the same size as <object> and <div>.


This is answered (with examples) in the svg primer.

tl;dr summary:

  • remove 'width' and 'height' attributes on the svg root, and add a 'viewBox' attribute with the value "0 0 w h", where w and h are the absolute values usually found in the width and height attributes (note that percentages and other units aren't allowed in the viewBox attribute)


add this to the parent div

#widget1 {
    display: flex;
    justify-content: center;
}


Try to add:

width: XXXpx !important;
height: XXXpx !important;
0

精彩评论

暂无评论...
验证码 换一张
取 消