html - 调整大小时删除嵌套 img 下的空白而不挤压图像

标签 html css fluid-layout fluid-images

我正在使用 div 和流体布局中的嵌套 img 制作基本标题。我对此有点生疏,而且我无法弄清楚如何确保嵌套在 div 中的图像缩放而不缩放到使其父 div 变小的程度。

EDIT: Updated the codepen link showing how using min-height won't work as it squeezes the image

HTML:

<div class="container">
  <div class="item half">
    <p>
      Some text
    </p>
  </div>
  <div class="item half">
    <img src="http://dummyimage.com/hd1080" class="full-width">
  </div>
</div>

CSS:

.container{
    margin: 0 auto;
    max-width: 1920px;
}

.item{
    height: 300px;
    float:left;
    overflow: hidden;
    background-color: gray;
}

.half{
    width: 50%
}

.full-width{
    max-width: 100%;
}

为了更好地衡量正在发生的事情的快速说明: enter image description here

以及我想要发生的事情的说明:

编辑:请注意,这里的图像没有被挤压,如果将图像的最小高度设置为等于其父div,就会发生这种情况。但溢出是隐藏的。您还可以看到我不介意图像被裁剪。 enter image description here

任何帮助表示赞赏。

最佳答案

您可以将等于 div.item 高度的 min-height 添加到图像 CSS

img {
    max-width:100%;
    min-height:300px;
}

关于html - 调整大小时删除嵌套 img 下的空白而不挤压图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32972282/

相关文章:

html - 如何让 element.scrollintoview 在位置 :fixed footer 下工作

html - 需要边框与 td 对齐

php - 如何通过php跳过段落中的某些单词

html - 流体网格 - 宽度百分比但出现水平滚动条

html - 在列表导航菜单中缩放背景图像的大小

html - 标题高度与流体布局

javascript - 允许多次按下按钮

javascript - jQuery 进度条宽度和数字动画不流畅

html - 如何通过CSS将长文本元素保持在同一行?

javascript - 使用ejs模板设置背景图片