简体   繁体   English

CSS Fluid布局和图像

[英]CSS Fluid layout and images

I am trying to create a completely fluid layout in CSS (everything in %), which would work seamlessly across platforms (desktop/mobile/tablets like iPad). 我正在尝试在CSS中创建一个完全流畅的布局(以%表示的所有内容),该布局将在各种平台(台式机/移动设备/平板电脑,如iPad)上无缝运行。

With Fluid Layouts, can an image be made completely fluid? 使用Fluid Layouts,可以使图像完全流畅吗? For example: 例如:

img { max-width:100%; }
  • Does this mean it will adjust/fit to any extent or window size? 这是否意味着它将调整/适合任何程度或窗口大小?
  • Also can this be applied to background images as well ? 这也可以应用于背景图像吗?
  • Does this property have any limitations in terms of browser implementation or anything ? 此属性在浏览器实现方面是否有任何限制?

The snippet you provide says that the maximum width for the image is 100% . 您提供的代码段显示图像的最大宽度为100% This could mean no wider than the browser window or device viewport. 这可能意味着不超过浏览器窗口或设备视口的宽度。 It could also mean no wider than a relatively postitioned parent node. 这也可能意味着没有比相对定位的父节点更宽的范围。 But, if the window is big enough, the image will render at it's native size. 但是,如果窗口足够大,则图像将以其原始大小进行渲染。

It can't be applied to background images, because the background image itself is tiled or positioned based on it's original size. 无法将其应用于背景图片,因为背景图片本身是根据其原始大小进行平铺或定位的。 The max-width trick is mostly useful for content images, not so much layout or styling images. max-width技巧最适用于内容图像,而不是布局或样式图像。

It is limited, in that IE6 doesn't support it at all. 局限性在于IE6完全不支持它。 However, that market is rather small and shrinking, so maybe you can ignore that issue. 但是,该市场规模很小且正在萎缩,因此也许您可以忽略该问题。

Your code means the size of the image relative to it's parent's width. 您的代码表示图片的尺寸相对于其父母的宽度。 So lets say the div that the image is in is 500px wide, then the image may be a maximum of 500px wide, or smaller, not larger. 因此,可以说图片所在的div宽度为500px,那么图片的最大宽度可能为500px,或更小或更大。 for more info on max-width: W3.org max-width 有关最大宽度的更多信息: W3.org最大宽度

For backgrounds this works a little different, you can use background-size: xy; 对于背景,这有点不同,您可以使用background-size: xy; for this. 为了这。 It's CSS3 and is not supported by older browsers. 它是CSS3,较旧的浏览器不支持。 for more info on background-size: W3.org background-size 有关background-size的更多信息: W3.org background-size

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

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