html - 如何摆脱 CSS 打印媒体中的八边形边框?
问题描述
尝试打印页面时出现边框问题。有人可以帮忙吗?
代码:
https://codepen.io/anon/pen/XPvQxw
body {
-webkit-print-color-adjust: exact !important;
}
header {
width: 100%;
}
header .small {
font-weight: 500;
}
.header__container {
max-width: 600px;
margin: 0 auto;
text-align: center;
padding: 0 15px;
}
.header__title {
font-family: 'Times New Roman';
font-weight: 700;
}
.header__separator {
border-top: 2px solid #fff;
margin-bottom: .5rem;
}
.bg {
position: relative;
background-color: blue;
color: #fff;
padding: 10px 0;
}
.bg:before, .bg:after {
content: "";
position: absolute;
}
.bg:before {
top: 0;
left: 0;
border-bottom: 20px solid blue;
border-left: 20px solid #FFF !important;
border-right: 20px solid #FFF !important;
width: 100%;
height: 0;
}
.bg:after {
bottom: 0;
left: 0;
border-top: 20px solid blue;
border-left: 20px solid #FFF !important;
border-right: 20px solid #FFF !important;
width: 100%;
height: 0;
}
.bg__container { position: relative; z-index: 100; }
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: inline-block; }
.list-item:before { content: '|'; font-weight: 300; font-size: .8rem; }
.list-item:first-child:before { content: none; margin-left: 0; }
.list-item a { color: #fff; text-transform: uppercase; font-size: 13px; font-weight: 500; text-decoration: none; margin-left: 6px; margin-right: 3px; }
.list-item a:hover { color: #ddd; }
.text-red { color: red; }
.text-blue { color: blue; }
.text-black { color: black; }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css">
<div class="container">
<header class="header bg mt-4 mb-4">
<div class="header__container bg__container">
<div class="header__top">
<h3 class="header__title">Title</h3>
<p class="h6">Sub-title</p>
<p class="h6 small">AND</p>
<p class="h6">Sub-title</p>
</div>
<hr class="header__separator">
<nav class="header__nav">
<ul class="header__nav-list list mb-1">
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
</ul>
<ul class="header__nav-list list">
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
</ul>
</nav>
</div>
</header>
解决方案
你可以尝试一些不同的背景来避免这种情况,这里有一个用渐变来创建白色角落的想法:
body {
-webkit-print-color-adjust: exact !important;
}
header {
width: 100%;
}
header .small {
font-weight: 500;
}
.header__container {
max-width: 600px;
margin: 0 auto;
text-align: center;
padding: 0 15px;
}
.header__title {
font-family: 'Times New Roman';
font-weight: 700;
}
.header__separator {
border-top: 2px solid #fff;
margin-bottom: .5rem;
}
.bg {
position: relative;
background:
linear-gradient(to top left, transparent 49.8%,#fff 50%) top left,
linear-gradient(to top right, transparent 49.8%,#fff 50%) top right,
linear-gradient(to bottom left, transparent 49.8%,#fff 50%) bottom left,
linear-gradient(to bottom right,transparent 49.8%,#fff 50%) bottom right,
blue;
background-size:20px 20px;
background-repeat:no-repeat;
color: #fff;
padding: 10px 0;
}
.bg__container {
position: relative;
z-index: 100;
}
.list {
list-style: none;
margin: 0;
padding: 0;
}
.list-item {
display: inline-block;
}
.list-item:before {
content: '|';
font-weight: 300;
font-size: .8rem;
}
.list-item:first-child:before {
content: none;
margin-left: 0;
}
.list-item a {
color: #fff;
text-transform: uppercase;
font-size: 13px;
font-weight: 500;
text-decoration: none;
margin-left: 6px;
margin-right: 3px;
}
.list-item a:hover {
color: #ddd;
}
.text-red {
color: red;
}
.text-blue {
color: blue;
}
.text-black {
color: black;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css">
<div class="container">
<header class="header bg mt-4 mb-4">
<div class="header__container bg__container">
<div class="header__top">
<h3 class="header__title">Title</h3>
<p class="h6">Sub-title</p>
<p class="h6 small">AND</p>
<p class="h6">Sub-title</p>
</div>
<hr class="header__separator">
<nav class="header__nav">
<ul class="header__nav-list list mb-1">
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
</ul>
<ul class="header__nav-list list">
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
<li class="header__nav-list-item list-item"><a href="#">home</a></li>
</ul>
</nav>
</div>
</header>
推荐阅读
- python - 在 Python 中遍历 FOR CURSOR
- css - 如何创建添加全局 css 文件的 ThemeProvider?
- amazon-web-services - CodeBuild 的动态存储库源和分支?
- javascript - Vue Slick Carousel 中的当前幻灯片总数
- hyperledger-fabric - 列出 Hyperledger Fabric 网络中的所有通道
- html - 如何使用 Flutter web 中的 universal_html 插件将字符串转换为 blob
- android-studio - 我可以在 Gradle 插件中配置 Kotlin 多平台模块吗?
- android - 针对 Android api 版本 30 的应用的 Flutter 相机包权限
- javascript - 如何根据数组对象javascript中的条件检查返回布尔值
- here-api - Here Maps 3.1 JS API 的样式文件