简体   繁体   English

css max-height 或 max-width 限制图像大小

[英]css max-height or max-width to restrict image size

Why should you not use max-height to restrict the size of an image?为什么不应该使用max-height来限制图像的大小?

Both max-width and max-height can be used to restrict the size of en element. max-widthmax-height都可以用来限制元素的大小。

This WC article suggests using max-width to fit the image in its container.这篇 WC 文章建议使用max-width使图像适合其容器。 https://www.w3.org/WAI/WCAG21/Techniques/css/C37 https://www.w3.org/WAI/WCAG21/Techniques/css/C37

Is there any reason not to use max-height to restrict size of an image should you have a web applicatin with vertical content flow ?如果您有一个具有垂直内容流的 web 应用程序,是否有任何理由不使用max-height来限制图像的大小?

https://developer.mozilla.org/en-US/docs/Web/CSS/max-height https://developer.mozilla.org/en-US/docs/Web/CSS/max-height

https://developer.mozilla.org/en-US/docs/Web/CSS/max-width https://developer.mozilla.org/en-US/docs/Web/CSS/max-width

max-height vs. max-width: the case for setting max-width最大高度与最大宽度:设置最大宽度的情况

  1. Setting both max-height and max-width can change the aspect ratio of the image, which is often not desired同时设置 max-height 和 max-width 可以改变图像的宽高比,这通常是不希望的
  2. Setting max-width can be used to ensure that the image "fit" horizontally.设置 max-width 可用于确保图像水平“适合”。 In most cases this is preferable, as people are used to scrolling web pages vertically, but not so much horizontally.在大多数情况下,这是更可取的,因为人们习惯于垂直滚动 web 页,而不是水平滚动那么多。

With that being said, it is up to you to determine which to use based on your requirements话虽如此,您可以根据自己的要求决定使用哪个

Yes.是的。 Some pages have content placed horizontally:)有些页面的内容是水平放置的:)

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

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