Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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/7/css/40.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/0/search/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
Html 为什么';t我的图像宽度从父div width继承_Html_Css - Fatal编程技术网

Html 为什么';t我的图像宽度从父div width继承

Html 为什么';t我的图像宽度从父div width继承,html,css,Html,Css,伙计们,我有一个这样的部门: <div id="image-container"> <img id="image" src="#" > //with an image inside </div> 但当我加载页面并检查图像上的元素以了解其尺寸时,它是这样说的: element.style { height: 600px; width: 600px; } 为什么图像不继承div的宽度?由于某些原因,我无法手动放置所需的图像宽度,因此我无法执行

伙计们,我有一个这样的部门:

<div id="image-container">
 <img id="image" src="#" > //with an image inside
</div>
但当我加载页面并检查图像上的元素以了解其尺寸时,它是这样说的:

element.style {
    height: 600px;
    width: 600px;
}
为什么图像不继承div的宽度?由于某些原因,我无法手动放置所需的图像宽度,因此我无法执行以下操作:

#image {
 width : 330px; //manually putting width
 height: 303px; //same same which i cannot do this for some reason
}
你知道为什么或者如何解决这个问题吗

我都尝试过下面的解决方案:

以下是我从inspect element得到的信息:

#image {
    height: inherit; // crossed-out
    width: inherit; // crossed-out
}
有东西正在覆盖我的图像尺寸

#image-container img { 
    width: inherit;
}

fiddle:

您应该将图像的
宽度
高度
属性设置为
100%
继承
或相同的值,以便完全填充父图像的空间

#Container {
    width: 200px;
    height: 200px;
}

#Image {
    width: inherit;
    height: inherit;
}
你可以查一下。另外,请确保文档中没有其他CSS加载到舒尔中。

试试这个

就足够了(以防我忘了怎么做)

我用的是bootstrap3。我有一个宽度为768px的列。我的标记如下所示:

<div class="col-lg-8">
    <img src="path/to/image.png" />
</div>
因此,其他图像(宽度较小)将使用其精确宽度

#image-container {
    width: 750px;
    height: 360px !important;
    text-align: center;
    overflow: hidden;
}

#image-container img{ 
    width: inherit;
}
#image {
    width: 100%;
    height: 100%;
}
<div class="col-lg-8">
    <img src="path/to/image.png" />
</div>
// parent div's width is currently 768px.
img { max-width: 100% }