【发布时间】:2019-12-04 12:16:12
【问题描述】:
我正在尝试为员工资料创建一个页面,其中显示图像名称和标题,然后单击箭头展开该员工的描述。
虽然我的 ul 设置为 2 列,但我的一切正常工作会导致一个问题,即扩展多个描述会缓慢地将该列中的底部 li 推到下一个。可能在下一列以半里结束。
理想情况下会发生的情况是 ul 只会扩展其高度以考虑描述中的额外高度。但是,一旦开始重叠,就将整个 li 推到下一列也是可以接受的。
有什么方法可以实现吗? JSFiddle
HTML:
<ul class="teams">
<li>
<div class="top">
<div class="imageWrap">
<img src="useruploads/user.png">
</div>
<div class="details">
<h2>Employee Name</h2>
<h4>Title</h4>
</div>
<div class="expander"><span><</span></div>
</div>
<div class="bottom">
<p>Description</p>
</div>
</li>
</ul>
CSS:
.teams {
margin: 1em auto;
padding: 0;
list-style: none;
columns: 2;
max-width: 1024px;
}
.teams li {
padding: 1em;
box-sizing: border-box;
margin-bottom: 1em;
}
.teams li .top {
display: flex;
flex-wrap: nowrap;
align-items: center;
height: 150px;
overflow: hidden;
}
.teams li .imageWrap {
width: 150px;
height: 150px;
background: #f3f3f3;
border-radius: 100%;
position: relative;
overflow: hidden;
}
.teams li .imageWrap img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
margin: auto;
margin-top: 1em;
box-sizing: border-box;
object-fit: cover;
break-inside: avoid-column;
}
.teams li .imageWrap:before {
content: "";
display: block;
padding-top: 100%;
}
.teams li .details {
margin-left: 1em;
width: calc(100% - 150px);
}
.teams li .top h2,
.teams li .top h4 {
margin: 0;
color: #5A96D3;
}
.teams li .bottom {
margin-top: 1em;
opacity: 0;
overflow: hidden;
max-height: 0;
background: #f3f3f3;
transition: max-height 1.5s ease;
}
.teams li .bottom p {
margin: 0;
padding: 1em;
box-szing: border-box;
}
.teams li .bottom#expanded {
opacity: 1;
overflow: hidden;
max-height: 100px;
transition: max-height 1.5s ease;
}
.teams li .expander {
border-radius: 100%;
background: #f3f3f3;
height: 35px;
width: 35px;
padding: 0.5em;
box-sizing: border-box;
margin-left: auto;
margin-right: 0;
cursor: pointer;
}
.teams li .expander span {
text-align: center;
display: block;
user-select: none;
transition: transform 0.5s ease;
}
.teams li .expander#closed > span {
transform: rotate(0deg);
}
.teams li .expander#open > span {
transform: rotate(-90deg);
}
【问题讨论】:
标签: css transition