html - CSS - 图像容器 div 与图像大小不同

标签 html css

我在容器 div 中有一个图像,下面是一个包含可以滚动的文本的 div。图像的大小可能会有所不同,因此图像的高度会根据所显示的图像而变化,即它并不总是像我的示例中那样为 400 x 200。

我的问题是,当文本滚动时,图像和文本应该在图像后面滚动的点之间有一个空间。这似乎是因为图像容器 div 与图像的大小不一样。

这个 JSFiddle 显示了问题 https://jsfiddle.net/t0ag2z5k/50/

谁能告诉我为什么会发生这种情况以及如何解决它?

下面的 CSS 代码...

#plotdetails {
    display: flex;
    flex-direction: column;
    float: left;
    width: 400px;
    z-index: 5;
    position: fixed;
    height: 100%;
}

#plotdetails #plot-img-container {
    display: inline-block;
}

#plotdetails #plot-img-container img{
    width: 400px;
    display: inline-block;
}

#details-text {
    padding: 0 20px 0 20px;
    overflow-y: scroll;
    flex: 1;  
}

这里是 HTML

<div id="plotdetails">
<div id="plot-img-container">
    <img src="http://placehold.it/400x200">
</div>
<div id="details-text">
    <h1>Lot's of words here....</h1>
</div>
</div>

最佳答案

为什么您希望您的图像在不被用作行内 block 时显示为行内 block ?尝试 ( https://jsfiddle.net/t0ag2z5k/52/ ):

#plotdetails #plot-img-container img{
    width: 400px;
    display: block;
}

关于html - CSS - 图像容器 div 与图像大小不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37468282/

相关文章:

HTML CSS IE7 表格溢出问题

css - 在 4 个 Angular 的 css3 中扭曲图像

css - 我无法在 Eclipse 中更改包资源管理器的字体大小

css - 使用上下文菜单隐藏和显示 'ng-repeat' 表行

jquery - 更改背景图像 css

asp.net - 在网页上重复内容

html - 将 div 的高度设置为屏幕高度,但随内容扩展

twitter-bootstrap - 一行内列的高度相等

html - 无法让导航列表内联显示

html - 列表内容居中