html - 打印 CSS 文件不更改网页
问题描述
我创建了一个打印 css 文件来处理我打印网页时对屏幕的更改。现在我已经编写了我的 Print Css 文件,因此不显示标题和导航,将所有字体更改为 Courier New,但由于某种原因,我的更改正在显示。我在我的代码中做错了什么?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link href="cpt330_styles.css" rel="stylesheet" type="text/css">
<link href="print.css" type="text/css" rel="stylesheet" media="print">
</head>
<body>
<header>
<img src="newark.jpg" alt="picture of Newark">
</header>
<nav>
<ul><a href="homework.html">Home</a></ul>
<ul><a href="websites.html">Favorite Websites</a></ul>
<ul><a href="meals.html">Favorite Meals</a></ul>
</nav>
<footer>
</footer>
</body>
</html>
Print.CSS File
header, nav
{
display: none;
}
html
{
font-family: Courier New;
}
ul
{
list-style-type: none;
}
解决方案
您可以使用打印样式表中的at 规则仅@media
在打印时应用您的 CSS 。
@media print {
header, nav {
display: none;
}
html {
font-family: Courier New;
}
ul {
list-style-type: none;
}
}
推荐阅读
- python - 发送到通道时接受参数
- python - 为什么与完全 nan 分类序列的相等和不等比较总是返回 False?
- javascript - 当我使用 insertAdjacentHTML("beforeend" ... 向 DOM 添加元素时出现神秘字符
- python - 用插座连接电脑
- firebase - 找不到 Firebase 管理模块无法解决“@firebase/app”NextJs
- javascript - json数据深度嵌套的datatable和ajax
- sas - SAS 自定义键 (F12) 清除但随后在没有命令的情况下运行脚本
- mysql - 将 Mediawiki 部署到 Azure:无 SSL 连接
- javascript - 如何在 React.JS 中正确交换数组元素?
- c++ - C++ 禁用子类中的重载运算符