css - max-height Transition 使子元素始终位于父元素的底部
问题描述
我正在与非常简单的问题作斗争。部分会在悬停时更改其最大高度。小跨度文章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;
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
我的问题是,鼠标离开时,白色标签会迅速跳起来。此外,我已经用165px
我无法预见的值定义了它的顶部,因为行具有不同的内容。
如何始终将标签定位在当前最大高度底部?
解决方案
始终将 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>
推荐阅读
- php - 如何使用 PHP 更新或更改数组
- python - 将数字转换为可变长度的二进制
- c++ - 为什么我在函数中创建的对象不会被其他函数修改?(C++)
- python - 检索解包需要8字节的缓冲区错误套接字python
- github - 有什么方法可以使用 Google Colab 在 GitHub 上发送 Pull Requests 和/或 Merge PRs?
- android - Flutter - 错误:此库已禁用空安全功能
- php - laravel 8 中的单元测试控制器
- rendering - 在虚幻引擎 4 中使用自定义组件渲染 obj 网格会呈现视觉伪影
- c# - 用户控件不更新文本框 mvvm WPF C#
- javascript - 预加载器屏幕淡出后播放 embed youtube