简体   繁体   English

CSS图像固定高度动态宽度

[英]CSS image fixed Height dynamic Width

I have a set of different images that I want to line up on a horizontal row. 我有一组不同的图像,我想在水平行上排队。 I want to set the height but keep the correct width. 我想设置高度但保持正确的宽度。 (dynamic width) (动态宽度)

The problem is that the width is the same for all pictures. 问题是所有图片的宽度都相同。

Any ideas? 有任何想法吗?

This is my markup and style: 这是我的标记和风格:

<div class="jumbo">
   <ul>
      <li><img src="picture1.jpg" /></li>
      <li><img src="picture2.jpg" /></li>
      <li><img src="picture3.jpg" /></li>
   </ul>
</div>

.jumbo ul {
  height: 430px;
  width: 20000px;
  margin-top:10px;
  /*border: 2px solid red;*/
}
.jumbo li {
  float: left;
  display: inline;
  margin-left: 70px;
}

.jumbo img {
    max-height:430px;
    width: auto;
}

Two ways to get proportional sizing. 两种获得比例尺寸的方法。 Either set the container (in your case ul) to a fixed height and then set the image height to 100% - don't state a width - the width will then be proportional to the height (that's what you want, right?). 将容器(在您的情况下为ul)设置为固定高度,然后将图像高度设置为100% - 不要说明宽度 - 宽度将与高度成正比(这就是您想要的,对吗?)。 Alternatively, just set the image height, and leave the width unstated - again, the width will be proportional. 或者,只需设置图像高度,并保持宽度不变 - 再次,宽度将成比例。

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

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