简体   繁体   English

当响应屏幕击中某些显示器时,如何使SVG图像具有特定大小?

[英]How to make SVG image a specific size when responsive screen hits certain display?

I don't know if I need to use javascript or not, but any idea how I can make a SVG image a specific size when the screen hits a certain display (example, 640×480 pixels)? 我不知道是否需要使用javascript,但是不知道如何在屏幕达到特定显示效果(例如640×480像素)时使SVG图像达到特定大小?

My SVG image is already responsive, but I want it to appear smaller in the mobile display. 我的SVG图像已经响应,但是我希望它在移动显示器中显得更小。

thanks! 谢谢!

You could have a section in your CSS something like: 您可以在CSS中添加以下内容:

@media screen and (max-width: 480px) {

  svg {
    max-width: 200px;
    max-height: 200px;
  }

}

markup 标记

  <svg 
    width="120" 
    height="120" 
    viewBox="0 0 120 120"
    xmlns="http://www.w3.org/2000/svg">
    <rect x="10" y="10" width="1000" height="1000"/>
  </svg>

</div>


styles 款式

svg { /* make it generally responsive */
  display: block;
  width: 100%;
  height: 100%;
}

.box {
  max-width: 300px;
}

@media (min-width: 600px) { /* when 600px and bigger */
  .box {
    max-width: 200px;
  }
}

https://jsfiddle.net/sheriffderek/z9fw1ndr/ https://jsfiddle.net/sheriffderek/z9fw1ndr/

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

相关问题 如何使这个 SVG 响应? - How to make this SVG responsive? 如何使图片轮播响应在移动尺寸上显示1张图片? - How can I make my image carousel responsive to display 1 image on mobile size? 如何使div左右保持2 div的div取决于屏幕大小 - how to make responsive a div holding 2 divs in the right and left with image depending on screen size 如何使我的 web 应用程序在更改屏幕大小和所有内容时响应更快? - How to make my web application more responsive when changing screen size and all? 与屏幕宽度相关的图像渲染大小未知时的响应图像 - Responsive images when image rendering size in relation to screen width is unknown 如何制作不同屏幕尺寸的响应式同位素库插件? - How to make a responsive isotope gallery plugin in different screen size? 显示当前屏幕大小 - 响应式设计工具 - Display current screen size - Responsive Design tools 在 Reactjs 中响应时如何获取图像大小或 div 大小 - How to get image size or div size when it's responsive in Reactjs 更改屏幕尺寸时如何删除功能(菜单响应式) - How to remove function when I change screen size (menu responsive) 缩小屏幕尺寸时如何在Css中使用响应设置重量和高度 - How to set weight and height in Css with responsive when reduce screen size
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM