简体   繁体   English

max-height Transition 使子元素始终位于父元素的底部

[英]max-height Transition keep child element always on bottom of parent

I'm fighting with quite easy problem.我正在与非常简单的问题作斗争。 Sections change their max-height on hover.部分更改了 hover 上的最大高度。 the small span article article__tag should always position at the bottom of its parent (the green line) no matter how much the row will grow and share its easing animation and delay.小跨度文章article__tag应该总是 position 在其父级(绿线)的底部,无论行将增长多少并共享其缓动 animation 和延迟。

This is what I have:这就是我所拥有的:

 section{ background: #000; color: #fff; display: flex; max-height: 150px; border-bottom: 1px solid lightgreen; transition: max-height.5s ease-in-out; position: relative; overflow: hidden; } section:hover { max-height: 400px; transition-delay: .3s; } article { flex:1; height: 200px }.article__tag { background: white; color: #000; position: absolute; padding: 10px; top: 120px; transition: all.5s ease-in-out; transition-delay: .3s; } section:hover.article__tag { bottom: 0; top: inherit; }
 <section> <article>A</article> <article><span class="article__tag">tag</span></article> </section> <section> <article>B</article> <article><span class="article__tag">tag</span></article> </section>

https://codepen.io/t-book/pen/LYpjVPz https://codepen.io/t-book/pen/LYpjVPz

My problem is, on mouse leave the white label jumps up quickly.我的问题是,鼠标离开时,白色的 label 会迅速跳起来。 Further, I've defined it's top with 165px a value which I cannot foresee as the rows have different content.此外,我用165px定义了它的顶部,这是一个我无法预见的值,因为行具有不同的内容。

How can I position the label always on current max-height bottom?我怎样才能 position label 总是在当前最大高度底部?

Keep article_tag at bottom always:始终将 article_tag 保持在底部:

 section{ background: #000; color: #fff; display: flex; max-height: 150px; border-bottom: 1px solid lightgreen; transition: max-height.5s ease-in-out; position: relative; overflow: hidden; } section:hover { max-height: 400px; transition-delay: .3s; } article { flex:1; height: 200px }.article__tag { background: white; color: #000; position: absolute; padding: 10px; bottom: 0px; transition: all.5s ease-in-out; transition-delay: .3s; }
 <section> <article>A</article> <article><span class="article__tag">tag</span></article> </section> <section> <article>B</article> <article><span class="article__tag">tag</span></article> </section>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM