简体   繁体   English

css 流体布局图像问题

[英]css fluid layout image issues

okay im making a layout that has two sides.好的,我正在制作一个有两侧的布局。 the left is 30% and the right 70%.左边是 30%,右边是 70%。 i have a widescreen monitor so all the images will display how i want them too with good room left.我有一个宽屏显示器,所以所有的图像都将显示我想要的方式,并且还有足够的空间。 BUT on lower resolutions and the most common 1024x768, the image i made is too big for the left side and goes out of the borders onto the right side.. how would i make the image automatically resize to fit on smaller resolutions?但是在较低的分辨率和最常见的 1024x768 上,我制作的图像对于左侧来说太大了,并且超出了右侧的边界.. 我如何使图像自动调整大小以适应较小的分辨率?

CSS CSS

#left {
  float:left;
  width:30%;
  height:100%;
  position:fixed;
  padding:20px;
}

#right {
  float:right;
  width:70%;
  height:100%;
  position:absolute;
  padding:40px 20px;
}
#left img {
  ??
}

Try using max-width and a percentage value on the image.尝试在图像上使用max-width和百分比值。 This way the image will never exceed that percentage.这样,图像将永远不会超过该百分比。

For example:例如:

img {
    max-width:90%;
}

Depending on your image, you could just add overflow: hidden on the #left div.根据您的图像,您可以在#left div 上添加overflow: hidden

One of the ways to do this is add the image to the background of the #left div .一种方法是将图像添加到#left div的背景中。

The image will not resize but it will also not flow over the borders.图像不会调整大小,但也不会流过边界。

You could make the background resize using CSS3, although there is not full browser support.您可以使用 CSS3 调整背景大小,尽管没有完整的浏览器支持。

background-size:100% 100%; will make sure the image sizes to the entire div .将确保图像大小为整个div However there may be some distortion.但是可能会有一些失真。

This will do it:这将做到:

#left img {
  width: 100%;
}

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

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