[英]Image 100% of parent. Parent is position fixed
Could somebody please assist. 可以请人帮忙。 I am trying get an image to have a
max-height
and an auto
width. 我正在尝试使图像具有
max-height
和auto
宽度。 The problem is these rules are being ignored as it's parent is fixed
问题是这些规则已被忽略,因为其父级是
fixed
DEMO http://jsfiddle.net/gop4jhm9/5/ 演示http://jsfiddle.net/gop4jhm9/5/
#myDiv {
position: fixed;
top: 100px;
left: 50%;
width: auto;
height: auto;
max-height: 100%;
background: red;
display: inline-block;
padding: 10px;
max-height: 30%;
}
#myDiv img {
width: auto;
height: 100%; // being ignored
}
Is there any way of doing this via CSS, JS, jquery ? 有没有办法通过CSS,JS,jquery做到这一点?
The problem is that you have the #myDiv
with two max-height
attributes. 问题是您具有两个
max-height
属性的#myDiv
。 Take away the second one, which restricts the div to 30%, and it will work in fixed. 删除第二个,将div限制为30%,它将固定工作。
That is because it intends to keep the image's aspect ratio because you set the margin to auto. 那是因为它打算保持图像的纵横比,因为您将边距设置为自动。 if you wish for a max height to be set, set it in the
max-height
property of the #myDiv.img
. 如果希望设置
max-height
,请在#myDiv.img
的max-height
属性中进行#myDiv.img
。
#myDiv {
position: fixed;
top: 100px;
left: 50%;
width: auto;
height: auto;
background: red;
display: inline-block;
padding: 10px;
}
#myDiv.img
{
width: auto;
max-height:90%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.