微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

伙计我有这样的div:
<div id="image-container">
 <img id="image" src="#" > //with an image inside
</div>

并以这种方式设计:

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

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

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元素得到的:

#image {
    height: inherit; // crossed-out
    width: inherit; // crossed-out
}

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

解决方法

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

#image-container img{ 
    width: inherit;
}

原文地址:https://www.jb51.cc/html/226147.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐