为什么我的图像宽度不是从父div宽度继承的

Bel*_*day 8 html css

伙计我有这样的div:

<div id="image-container">
 <img id="image" src="#" > //with an image inside
</div>
Run Code Online (Sandbox Code Playgroud)

并以这种方式设计:

#image-container {
    width: 750px;
    height: 360px !important;
    text-align: center;
}
Run Code Online (Sandbox Code Playgroud)

但是当我加载页面并检查图像上的元素以了解其尺寸时,这就是它所说的:

element.style {
    height: 600px;
    width: 600px;
}
Run Code Online (Sandbox Code Playgroud)

为什么图像不继承div的宽度?由于某种原因,我无法手动设置所需的图像宽度,所以我不能这样做:

#image {
 width : 330px; //manually putting width
 height: 303px; //same same which i cannot do this for some reason
}
Run Code Online (Sandbox Code Playgroud)

知道为什么或如何解决这个问题?

我都尝试过以下解决方案:

这是我从inspect元素得到的:

#image {
    height: inherit; // crossed-out
    width: inherit; // crossed-out
}
Run Code Online (Sandbox Code Playgroud)

有些东西会覆盖我的图像尺寸.

小智 7

试试这个FIDDLE

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

#image-container img{ 
    width: inherit;
}
Run Code Online (Sandbox Code Playgroud)


小智 6

#image-container img { 
    width: inherit;
}
Run Code Online (Sandbox Code Playgroud)

小提琴:关于继承宽度