SVG height incorrectly calculated in Webkit browsers

后端 未结 9 438
轻奢々
轻奢々 2020-12-24 12:26

I have a issue specific to Webkit browsers (Safari & Chrome, on Mac & PC).

I\'m using Raphael JS to render SVG data and using a responsive layout to scale th

9条回答
  •  囚心锁ツ
    2020-12-24 12:51

    It's hard for me to understand exactly what you want with your example, or what is not as you intend it. However, in general, if you are using a layout with percentage widths and height containers and you want content to fill those containers, you need to take them out of the flow (using position:absolute on the content and position:relative or position:absolute on the containers).

    Here's a simple example that works find in Chrome and Safari:
    http://phrogz.net/SVG/size-to-fill.xhtml

    The #foo div has its height and width as a percentage of the body. It has a red background that will never be seen because the SVG is position:absolute inside it and set to fill it completely, and have a green background. If you ever see red, it is an error.

    #foo, svg { position:absolute }
    #foo { left:20%; width:30%; top:5%; height:80%; background:red; }
    svg  { top:0; left:0; width:100%; height:100%;  background:green; }
    

提交回复
热议问题