html - 没有最后一个孩子的 CSS 属性
问题描述
我想添加一条灰色线来分隔红色 div,最终结果应该是: 在此处输入图像描述
我在消除最后一个红色 div 之后的行时遇到问题,我的代码是:
<html>
<head>
<style>
.authorsContainer{
padding-right: 15px;
padding-left: 15px;
}
.authorIconVisibility, .authorName{
float:left;
}
.booksContainer{
display: flex;
clear: both;
}
.bookContainer{
float: left;
flex: 1;
}
.bookInfo{
position: relative;
background: green;
}
.bookInfo:after{
position: absolute;
content: "";
background: #ccc;
height: 2px;
left: 25%;
right: 25%;
margin-top: 5px;
}
.bookName, .bookYear{
text-align: center;
}
.bookDescription{
position: relative;
background: red;
min-height: 100px;
margin: 10px;
}
.bookDescription:after{
position: absolute;
content: "";
background: #ccc;
width: 2px;
top: 25%;
bottom: 25%;
right: -10px;
}
</style>
</head>
<body>
<div class="authorsContainer">
<div class="authorContainer">
<div class="authorInfo">
<div class="authorIconVisibility">icon</div>
<div class="authorName">name</div>
</div>
<div class="booksContainer">
<div class="bookContainer">
<div class="bookInfo">
<div class="bookName">n1</div>
<div class="bookYear">y1</div>
</div>
<div class="bookDescription">
</div>
</div>
<div class="bookContainer">
<div class="bookInfo">
<div class="bookName">n2</div>
<div class="bookYear">y2</div>
</div>
<div class="bookDescription">
</div>
</div>
<div class="bookContainer">
<div class="bookInfo">
<div class="bookName">n3</div>
<div class="bookYear">y3</div>
</div>
<div class="bookDescription">
</div>
</div>
</div>
</div>
</div>
</body>
</html>
我试图将最后一个 CSS 选择器更改为
.bookContainer .bookDescription:not(:last-child):after{
position: absolute;
content: "";
background: #111;
width: 2px;
top: 25%;
bottom: 25%;
right: -10px;
}
但它不起作用(根本没有线条)。
我应该改变什么?
解决方案
推荐阅读
- excel - 循环比较列中的值,如果不同则插入新行,但如果第一行是唯一值则忽略第一行
- c - 给定一个 int 偏移向量,如何使用 AVX512 内在函数收集单个字节?
- c# - ListBox .NET Framework 中的 Mouse Up 事件问题
- python-3.x - 没有名为“dlib”的模块
- css - Spring 安全性与 *.css 和 *.js 文件
- c# - 当其中一个部分的类型未知时,从元组中获取项目
- php - 如何停止复制子目录?
- android - 避免每次都做 adb tcpip 5555
- linux - include/config/auto.conf.cmd : 没有这样的文件或目录 [Kali Linux]
- javascript - 为什么我在 Vue 中的移动标签效果不起作用?