有时div中的内容会展开以适应父级宽度,但有时内容(如img、table)会使父文件扩展。第一种或后一种情况会在什么情况下发生?
发布于 2014-04-04 05:08:08
考虑一下HTML
<div class='content'>
<img src=" your img source " />
</div>
展开div的内容以适应父级宽度,如果您指定内部内容宽度的话。
a)
定高定宽
例如
.content{
width:500px;
height:500px;
}
.content .img{
width:100%; // in this case the image will be stretched or compressed to fit the div exactly
height:100%;
}
注:在上述情况下,img的高度和宽度将始终达到500 of要求的分辨率。
b)
定宽
例如
.content{
width:500px;
}
.content .img{
width:100%; // in this case the image will be stretched or compressed to fit the div exactly
}
注意:
在上述情况下,我们没有固定.content
或.content img
的高度,因此高度或宽度将根据图像大小自动调整。因此,如果图像的高度为400 as,则.content
div的高度为400 as,如果图像的高度为50 as,则.content
div的高度为50 as。
c)不固定宽度和高度
例如
/* No style specified */
注意:
在上述情况下,.content
div的高度和宽度将根据图像的大小而定,因此,如果图像的分辨率为500 if *900 if,则div的宽度和高度分别为500 if和900 if。
https://stackoverflow.com/questions/22853429
复制相似问题