简体   繁体   English

如何仅为打印预览调整svg图像的大小?

[英]How to resizing svg images for a print preview only?

Right now I have some d3 graphs that on the page that listen to the screen resize event and can be enlarged quite large. 现在,我在页面上有一些d3图表,它们监听屏幕调整大小事件,并且可以放大得很大。 However when a user goes to print them they are too big for the printed page. 但是,当用户去打印它们时,它们对于打印页面来说太大了。 If I limit the size of the svg's then if the screen is resized really wide then they wont scale. 如果我限制svg的大小,则如果屏幕的尺寸真的很宽,那么它们将无法缩放。

In other words I need my svg's to be a certain size in the print preview yet still scale in the browser view port. 换句话说,我需要在打印预览中将svg设置为一定大小,但仍要在浏览器查看端口中缩放。 How could one accomplish this? 一个人怎么能做到这一点?

You should be able to use media queries to scale the graphs. 您应该能够使用媒体查询来缩放图形。 https://developer.mozilla.org/en-US/docs/Web/CSS/@media https://developer.mozilla.org/en-US/docs/Web/CSS/@media

For example: 例如:

@media print { 
    svg {
        width: 3in;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM