css - 100% 宽度的 html img,并剪裁到父元素的高度,这是不固定的

标签 css twitter-bootstrap

我有一张图片,'img.icon-avatar set in some html: http://jsbin.com/moqagu/5/edit?html,css,output

我如何强制图像为 100% 宽度(就像现在一样),但剪裁到它的父元素的高度,所以(在示例中)它不会将下一个面板向下推,并尊重或包含填充?

html:

<div class="row">
    <div class="col-xs-3">
      <div class="icon-avatar">
        <img class="icon-avatar img-rounded" src="http://s3.amazonaws.com/37assets/svn/765-default-avatar.png" alt="avatar"/>
      </div>
    </div>
    <div class="col-xs-9">
      <div class="panel panel-primary">
        <div class="panel-heading">

          <h3 class="panel-title">
            Title
          </h3>
        </div>
        <div class="panel-body">
            Content
        </div>
      </div> <!--panel -->
    </div>
  </div> <!-- row -->

CSS:

div.icon-avatar {
  ?
}

img.icon-avatar {
  width:100%;
  ?
}

注意父元素的高度不是固定的,会根据页面上的其他元素而定,所以我需要父元素在确定自己的高度时忽略图片。

最佳答案

像那样:

div.icon-avatar {
  text-align: center
}

img.icon-avatar {
  width:auto;
  max-height:90px;
}

关于css - 100% 宽度的 html img,并剪裁到父元素的高度,这是不固定的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39186024/

相关文章:

css - Material Angular 选择下拉列表完全在应用程序根之外呈现

html - 使用 Bootstrap 4 在移动设备上内嵌导航栏图标?

javascript - 如何将 json 响应显示回网页?

javascript - 在页面加载 AngularJS 时启动 Bootstrap 模式

html - 如何交替表格中的列背景颜色?

html - Bootstrap 粘性页脚存在小宽度页面的问题

html - 是否可以通过在 HTML 和 CSS 中创建表格来实现

html - 具有最大高度而不是最大宽度的流体图像

html - 辅助功能 - Bootstrap4 Carousel 控件在使用键盘上的 tab 键时不会转到 carousel-caption div

php - 在 CSS 中缓存 Busting 图像