html - 图像未占据带有动态文本的 div 旁边容器的全高

标签 html css image height

我目前正面临一个问题,因为我正在尝试使具有未固定文本的 div 旁边的全高图像适合。

我已经尝试将最大宽度和最大高度设置为 100%,但没有成功,还有背景图片,但仍然找不到解决方案。

这是我的标记:

<div class="col-xs-6 containerDivs">
    <div class="col-xs-8">
        <h2>LOREM IPSUM</h2>    
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do          
       tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
       veniam, quis nostrud exercitation ullamco laboris nisi u</p>
        <a href="#"><i class="moreIcon white spinLeft"></i></a>
    </div>
    <div class="col-xs-4">
        <img src="img/image-1.jpg">
    </div>
</div>

这是我的 CSS:

  .containerDivs{           
        > div:first-child{
            background-color:grey;              
            padding: 20px;
            h2{
                font-family: 'Lounge-Bold', Helvetica, sans-serif;
                font-size: 30px;                                                    
                letter-spacing: 6px;                    
                margin-bottom: 30px;
            }
            h2,p{
                color: white;
                text-transform: uppercase;
            }
            p{
                line-height: 1.8;
                font-family: 'Lounge', Helvetica, sans-serif;
                font-size: 16px;                        
            }
        }
        > div:last-child{           
            
        }
        
    }

这是它现在在我的浏览器中的样子:

Full height problem

所以我缺少的是图像占据列的整个高度,如果图像的一部分被裁剪也没关系,只要它占据整个高度。

最佳答案

您可以使用 Flexbox让两个 div 处于相同的高度。

/* Add it to the parent */
.containerDivs{
   display: flex;
} 

关于 img,如果你想让它全高,我建议你在 div 上使用 background-image :

.containerDivs>div:last-child{           
  background-image: url("path_to_your_image");
  background-size:cover;
}

这是一个有效的 JsFiddle:DEMO

关于html - 图像未占据带有动态文本的 div 旁边容器的全高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37770570/

相关文章:

javascript - 为什么这些图像比原始尺寸大?

javascript - 无法以正确的方式附加子项

Javascript:链接到按钮的功能不起作用

html - 在文本下方居中一条小线

javascript - 使所有表的列与第一个表的列具有相同的宽度

firefox 的 html5 范围标签问题?

HTML 对齐元素和字体颜色

html - 拉丁字符显示在页面的某些部分而不是其他部分

java - 在 Java 中识别图像中的相似模式

html - 如何制作来自 CMS 的响应式背景图像?