1 回答
TA贡献1818条经验 获得超3个赞
您可以依靠相对/绝对位置来使用父级作为参考。
例子 :
.messages__list__item {
position: relative;
margin-top: 1.2em;
}
.message-full-date {
position: absolute;
bottom: 100%;
left: 0;
right: 0;
width: max-content;
margin: auto;
}
.flex {display:flex;}
.flex li {flex:1}
/* see us */
li , .message-full-date{border:solid 1px;}
<div class="messages">
<ul class='messages__list'>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item">
<span class="message-full-date">date</span>
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item">
<span class="message-full-date">date</span>
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
</ul>
</div>
<div class="messages">
<ul class='messages__list flex '>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item">
<span class="message-full-date">date</span>
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item">
<span class="message-full-date">date</span>
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item">
<span class="message-full-date">date</span>
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item">
<span class="message-full-date">date</span>
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item">
<span class="message-full-date">date</span>
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
</ul>
</div>
如果必须显示日期,您还可以使用 ::before 伪值来生成此容器
li.message-full-date:not([data-date=""]) {
margin: 2px 0 0 0;/* possibly useful */
}
.flex li.message-full-date:not([data-date=""]) {
margin: 0 0 0 2px ;/* possibly useful */
}
.message-full-date:not([data-date=""])::before {
content: 'date :'attr(data-date);
display: block;
width: max-content;
margin: auto;
}
.flex {
display: flex;
}
.flex li {
flex: 1
}
/* see us */
li,
.message-full-date::before {
border: solid 1px;
}
<div class="messages">
<ul class='messages__list'>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item message-full-date" data-date="01/01/01">
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
</ul>
</div>
<div class="messages">
<ul class='messages__list flex'>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item message-full-date" data-date="01/01/01">
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item message-full-date" data-date="">
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
<li *ngFor="let msg of currConversation.messages" class="messages__list__item message-full-date" data-date="01/02/01">
<p class="message message-name">name</p>
<p class="message message-content">content</p>
</li>
</ul>
</div>
- 1 回答
- 0 关注
- 87 浏览
添加回答
举报