繁体   English   中英

为什么子元素 <img /> 父div的宽度和高度中不包含?

[英]why child element <img /> not contains in the parent div width and height?

每个人我尝试的CSS样式如下:

.image{
        position: absolute;
        width: 100px;
        height:100px;
        padding: 5px;
        margin: 0;
        background-color:green;
    }
    <div class="image">
        <img src="http://www.wallpapersgo.com/wp-content/uploads/2010/02/Dodge-Charger-Car.jpg"/>
    </div>

问题是,显示的图像大小与原来的大小相同,但预期的大小不是100px * 100px。 CSS风格的新鲜,需要帮助,谢谢!

采用:

.image{
        position: absolute;
        width: 100px;
        height:100px;
        padding: 5px;
        margin: 0;
        background-color:green;
    }

.image img {       
        width: inherit;
        height:inherit;
    }

只需添加

.image img{
  height: 100%;
  width: 100%;
}

http://jsfiddle.net/p67dh/

这是因为您的图像不会自动使用父元素的大小。

暂无
暂无

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

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