html - CSS 正文作者样式不适用,无法覆盖用户代理样式表
问题描述
我在 HTML 根元素中设置了字体大小,以便在项目中使用 rem 单位。之后,我无法在 body 元素上应用任何样式。检查器显示它正在使用用户代理默认样式表。其他样式确实适用,但 body 元素完全被破坏了。
在 Chrome、Firefox 和 Safari 中也是如此。字体系列、颜色、填充等也都被破坏了。
如果需要,您可以通过此链接下载该项目。
如果我注释掉 * 和 HTML 选择器,填充、字体系列又回来了,但由于默认的 16px 字体大小,rems 不正确。
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 10px;
}
body {
font-family: "Lato", sans-serif;
font-weight: 400;
line-height: 1.7;
color: #777;
padding: 30px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet">
<link rel="stylesheet" href="./css/style.css">
<link rel="shortcut icon" type="image/png" href="img/favicon.png">
<title>Natours</title>
</head>
<body>
<header class="header">
<div class="logo-container">
<img src="./img/logo-white.png" class="logo" alt="natours logo">
</div>
<div class="heading-container">
<h1 class="heading-primary">
<span class="heading-primary-main">Outdoors</span>
<span class="heading-primary-sub">is where life happens</span>
</h1>
<a href="#" class="btn btn-white btn-animated">Discover our tours</a>
</div>
</header>
</body>
</html>
如何正确设置根字体大小以使用 rems?是什么导致了这个问题?
解决方案
这很奇怪。我复制,打开,关闭文件十次。然后将 html 选择器删除(未注释)并再次重写。这解决了这个问题。我以前从未见过这样的事情。
推荐阅读
- c# - 如何更改 nswag 生成的默认信息标题?
- html - 如何在VSCode中将html属性格式化为垂直列表
- node.js - 意外的令牌“缩进”想要使用 node.js(app.js) 在玉文件上呈现并得到这个错误“意外的令牌“缩进”
- r - 基于“typeof”列表列删除 R 中的行
- java - 具有多个身份验证的 Spring Security
- c# - 我将如何使用另一个类的另一种方法
- react-native - FCM 定期通知在第二天不起作用
- javascript - 禁用按钮会破坏 php post
- php - 在我的带有 IN 数组的 SQL 语句中出现 bind_param() 错误?
- python - 在 matplotlib 中注释子图将图形缩放到最大轴