【发布时间】:2019-10-08 05:41:26
【问题描述】:
我正在生成 pdf。我想使用 css 方法删除最后一页,我正在尝试获取 :last-child 以删除它,但结果什么都没有。
我的代码:
body {
font-family: 'Roboto', sans-serif;
font-size: 0.85em;
padding-left: 30px;
padding-right: 30px;
line-height: 0.95em;
}
@font-face {
font-family: 'Roboto', sans-serif;
font-style: normal;
font-weight: normal;
}
footer {
position: fixed;
bottom: -30px;
right: 0px;
height: 50px;
width: 270px;
text-align: left;
}
footer .page-number:after {
content: counter(page);
}
footer .page-number .last:last-child {
display: none
}
<body>
<footer>
<div class="right" style="margin-left: -85px;">
<span class="page-number"></span>
</div>
<table width="100%" class="last">
<tr>
<td>
<span style="
border: 1px solid;
box-sizing: border-box;padding-right: 0.88cm;padding-left: 5px;vertical-align: middle;">Roles I </span>
<span style="width: 300px;
border-top: 1px solid;
border-right: 1px solid;
border-bottom: 1px solid;
margin-left: -6px;
box-sizing: border-box;padding-right: 70px;vertical-align: middle;">     </span><br>
<span style="
border-left: 1px solid;
border-right: 1px solid;
border-bottom: 1px solid;
box-sizing: border-box;padding-right: 1.32cm;padding-left: 5px;vertical-align: middle;">Roles II</span>
<span style="width: 300px;
border-right: 1px solid;
border-bottom: 1px solid;
margin-left: -6px;
box-sizing: border-box;padding-right: 70px;vertical-align: middle; ">     </span>
</td>
</tr>
</table>
</footer>
MY content here until N - Page and i want to remove the last footer
</body>
正如您在这张图片的示例中看到的那样,我有 3 页,页脚中有我标记为红色的数字和框。我只是想删除红框中的数据,但是对于页码部分我不想删除它。
注意:我使用的是 dompdf 库
【问题讨论】:
-
.last不是.page-number的子级。事实上,他们甚至不是兄弟姐妹。你的选择器没有意义。也许您正在寻找footer:last-of-type .page-number, footer:last-of-type .last -
:last-child定位在伪元素之前与给定选择器匹配的最后一个子元素。但是,您的选择器不会匹配任何内容。问题不是:last-child,而是它之前的选择器。 -
我正在使用这个
footer:last-of-type .page-number, footer:last-of-type .last { display: none; }跟踪你的代码,我所有的页脚都消失了,使用这个footer:last-of-type .page-number {display: none}我所有的页码都消失了,使用这个footer:last-of-type .last { display: none; }我所有的红框没了 -
你的页脚不能是兄弟姐妹。伪是相对于直接父级的,因此您必须针对同级元素。我做了一个完整的答案以获得更多解释。