简体   繁体   English

图片无法正确放入div

[英]Image wont fit into div properly

so what I'm trying to accomplish is to have a large image, in this case a map, inside a smaller div with scroll bars that let you look at the rest of the map. 因此,我要完成的工作是在一个较小的div(具有滚动条)中放一个大图像(在本例中为一张地图),让您查看地图的其余部分。 I'm using class="img-responsive" at the moment but it makes the image the same size as the div which i do not want since when the user is looking for a road if the map is too small they wont be able to see it. 我目前正在使用class =“ img-sensitive”,但它使图像的大小与我不想要的div相同,因为如果地图太小,当用户正在寻找道路时,他们将无法看见。 I also tried to set a max-height for the div but the image is overflowing onto the background. 我还尝试为div设置最大高度,但是图像溢出到了背景上。 Please help. 请帮忙。

 .ibox-content { background-color: #ffffff; color: inherit; padding: 15px 20px 20px 20px; border-color: #e7eaec; border-image: none; border-style: solid solid none; border-width: 1px 0px; max-height: 350px; } 
 <div class="ibox-content" id="ibox-1"> <div class="active content" id="elementMap"> <img class="img-responsive" src="//lorempixel.com/600/600"> </div> </div> 

Remove img-responsive , because it gives the style max-width: 100% to the element, meaning the image can never be wider than its parent. 删除img-responsive ,因为它为元素提供了max-width: 100%样式,这意味着图像永远不会比其父元素宽。

Add overflow: auto; 添加overflow: auto; to the container: 到容器:

.ibox-content {
    background-color: #ffffff;
    color: inherit;
    padding: 15px 20px 20px 20px;
    border-color: #e7eaec;
    border-image: none;
    border-style: solid solid none;
    border-width: 1px 0px;
    max-height:350px;
    overflow: auto;
}

Div有溢出:滚动或溢出:自动将解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM