Html 使用引导响应图像限制图像高度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19708979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:55:52  来源:igfitidea点击:

Constraining image height with bootstrap responsive image?

htmlcsstwitter-bootstrap

提问by Adam Tracksler

Working on a site using bootstrap, in the portfolio section, the images of projects are responsive with :

使用引导程序在网站上工作,在投资组合部分,项目的图像响应于:

'class' => 'img-responsive'

It works great for landscape images, the portrait images are blown up to fit width wise, but are too tall, is there a way to check for a portrait orientated image and just apply a fixed height of 600px for it?

它适用于风景图像,人像图像被放大以适应宽度,但太高了,有没有办法检查纵向图像并为其应用 600px 的固定高度?

回答by MrPeeps

If the container should have a fixed height, then give it an ID (or a class) and change the .img-responsive restrictions the other way around eg

如果容器应该有一个固定的高度,那么给它一个 ID(或一个类)并以相反的方式更改 .img-responsive 限制,例如

.container {
height: 600px;
}


/*And then change */
  .container .img-responsive {
    display: block;
    height: auto;
    max-width: 100%;
}  
/*To */

.container  .img-responsive {
    display: block;
    width: auto;
    max-height: 100%;
}

Not sure how it will work with a mix of orientations but if they are floated it shouldnt really matter

不知道它如何在混合方向上工作,但如果它们是浮动的,那应该无关紧要