Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 为什么是子元素<;img/>;父div宽度和高度中是否不包含?_Css_Image_Html - Fatal编程技术网

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

Css 为什么是子元素<;img/>;父div宽度和高度中是否不包含?,css,image,html,Css,Image,Html,每个人我都尝试了css样式,如下所示: .image{ position: absolute; width: 100px; height:100px; padding: 5px; margin: 0; background-color:green; } <div class="image"> <img src="http://www.wallpaper

每个人我都尝试了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>
.image{
位置:绝对位置;
宽度:100px;
高度:100px;
填充物:5px;
保证金:0;
背景颜色:绿色;
}
问题是,显示的图像大小与实际大小相同,但不是预期的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%;
}

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