Css 为什么是子元素<;img/>;父div宽度和高度中是否不包含?
每个人我都尝试了css样式,如下所示: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
.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%;
}
这是因为图像不会自动使用父元素的大小