css - 在同一类的所有元素上应用 ::after
问题描述
我试图在类的每个元素之后显示一行。我希望为每个作者元素显示该行,但之后仅引用第一个元素。
这是一个项目,我想在每个元素作者后跟一行,目前所有::after
的 s 都指的是同一个元素:
.youtube-author:after {
content: "";
position: absolute;
bottom: 0;
left: 342px;
right: 0;
height: 0.5em;
border-top: 1px solid black;
z-index: -1;
color: #1e4671;
}
<div class="youtube-video-item">
<div class="youtube-img-next" onclick="replaceVideo('https://www.youtube.com/watch?v=JrBLYLFl_VE')"> <img height="80" width="120" src="https://i.ytimg.com/vi/JrBLYLFl_VE/hqdefault.jpg"></div>
<div class="youtube-title" onclick="replaceVideo('https://www.youtube.com/watch?v=JrBLYLFl_VE')">Breizh Storming. Les noms de famille (1)</div>
<div class="youtube-author">Author</div>
</div>
解决方案
position: relative
你在youtube-author
班上不见了。您必须将它们添加到父元素(真实元素)中才能将伪元素附加到它,否则它会转到相对定位的父元素:
.youtube-author {
position: relative;
}
.youtube-author:after {
content: "";
position: absolute;
bottom: 0;
left: 342px;
right: 0;
height: 0.5em;
border-top: 1px solid black;
z-index: -1;
color: #1e4671;
}
<div class="youtube-video-item">
<div class="youtube-img-next" onclick="replaceVideo('https://www.youtube.com/watch?v=JrBLYLFl_VE')"> <img height="80" width="120" src="https://i.ytimg.com/vi/JrBLYLFl_VE/hqdefault.jpg"></div>
<div class="youtube-title" onclick="replaceVideo('https://www.youtube.com/watch?v=JrBLYLFl_VE')">Breizh Storming. Les noms de famille (1)</div>
<div class="youtube-author">Author</div>
</div>
推荐阅读
- python - 通过对另一列的值求和来获取列的平均值
- hibernate - JPA:如何使用 Criteria API 管理未映射的表
- android - 如何在 Flutter 中定义 Shared_Preferences 的 MODE
- sql - 如何在 SQL Server 中同时转置表并进行聚合?
- c# - Moq VerifyNoOtherCalls() 方法的 NSubstitute 等效项是什么
- javascript - 如果 div 表已知,Javascript 从外部 url 获取数据
- vim - Neovim 中的 Python 折叠
- android - Android/JVM SQLite 数据库
- php - Nginx FastCGI 缓存 + Wp-Rocket + Google Pagespeed 重定向到 example.com/*/ 上的同一页面
- azure - 使用 Azure 数据工厂从 SFTP 获取 ZIP 文件到 Azure Datalake 并将其存储为 CSV 格式