gpt4 book ai didi

css - nth-child() 不显示在打印媒体中

转载 作者:行者123 更新时间:2023-12-04 20:42:38 24 4
gpt4 key购买 nike

忽略由 div 组成的表格(相信我,我已经与权力进行了讨论),我无法让我的交替行背景颜色查看我的打印媒体。这是我所拥有的:

<div class="table">
<div class="head">
<div class="headcell">Column 1 is this long</div>
<div class="headcell">Column 2 but this neeeds to be this long</div>
<div class="headcell">Column 3</div>
</div>
<div class="row">
<div class="cell">Column 1 is this long</div>
<div class="cell">Column 2 but this neeeds to be this lonn</div>
<div class="cell">Column 3</div>
</div>
<div class="row">
<div class="cell">Column 1</div>
<div class="cell">Column 2</div>
<div class="cell">Column 3</div>
</div>
<div class="row">
<div class="cell">Column 1</div>
<div class="cell">Column 2</div>
<div class="cell">Column 3</div>
</div>
<div class="row">
<div class="cell">Column 1</div>
<div class="cell">Column 2</div>
<div class="cell">Column 3</div>
</div>
<div class="row">
<div class="cell">Column 1</div>
<div class="cell">Column 2</div>
<div class="cell">Column 3</div>
</div>
</div>

还有我的 CSS:
@media print
{
h1 {
margin-top: 17.67pt;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: bold;
font-style: normal;
font-size: 16pt;
margin-bottom: 1.67pt;
padding-left: none;
background-image: none;
text-decoration: underline !important;
}

/*Table made of Divs PDF Styles*/
.table {
font-family: sans-serif;
font-size: 12px;
display: table;
width: 80%;
margin: 20px;
}

.head {
display: table-row;
border: #ccc 1px solid;
padding:4px 10px;
text-align:center;
font-weight: bold;
background-color: #ccc;
}

.row {
display: table-row;
border: #ccc 1px solid;
}

.headcell {
display: table-cell;
border: #ccc 1px solid;
padding: 10px;
font-align: center;
}

.cell {
display: table-cell;
padding: 10px;
border: #ccc 1px solid;
}

div.row:nth-child(odd) {
background-color: #ccc;
}

div.row:nth-child(even) {
background-color: #fff;
}
}

我感谢大家的帮助!

最佳答案

您不能强制打印最终用户打印背景颜色。这是浏览器中的打印机设置,可以关闭。这就是为什么它不起作用。
你的 nth-child 选择器工作得很好。请参阅下面的打印预览屏幕截图。

http://jsfiddle.net/Gjf8K/3/

 @media print {
div.row:nth-child(odd) {
background-color: #ccc;
color: red;
}
div.row:nth-child(even) {
background-color: #fff;
color: green;
}
}

print preview

关于css - nth-child() 不显示在打印媒体中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23372405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com