![](/img/trans.png)
[英]How to use JavaScript to show/hide an element based on its parent's dynamic height?
[英]How to hide a fixed element if outside of it's parent element's height?
我想知道如何隐藏.fixedElement
.entry-content
的.header(blue section)
,一旦.fixedElement到达顶部/底部,就不允许它显示在.header(blue section)
或.footer(green section)
上它是父元素,因此将其隐藏。
我了解到固定元素在其父元素css样式内不起作用,因为它基于浏览器的视口。
我认为创建一个示例会容易得多。
如果可能的话,我也会尽可能地使用javascript。
父级CSS: {overflow:hidden;}
编辑:专门:
<div class='some-tough-edges'>buncho stuffs</div>
.some-tough-edges { width: yourchoice; height: yourchoice; overflow: hidden; //display: block; if not using a block element }
edit2:不要在溢出内使用固定,在容器上固定位置以及容器内绝对或相对
可能最简单的方法是使.the_content
成为绝对元素,然后使用z-index像这样:
.fixedElement { position: fixed; z-index: 1; }
.the_content { position: absolute; z-index: 2; }
如果.the_content
是动态的,请在Javascript中调整其高度和位置。
在Javascript中调整高度和位置比在其中实现这种效果要容易得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.