您好,我对HTML和CSS不是很熟悉,遇到了一个奇怪的问题。我尝试使用样式和p选择器更改文本颜色,只要同时使用h1选择器就可以正常工作。这是我的代码:
<!DOCTYPE html> <!-- Indicates which HTML version is being used -->
<html> <!-- HTML starts here --> <!-- Also called root element -->
<head> <!-- background/setup information goes inside head -->
<meta charset = "utf-8" /> <!-- defines character set -->
<title> Hello Internet! </title> <!-- website title name -->
<style type = "text/css"> <!-- Added for CSS -->
h1{
}
p{
color: red;
}
</style>
</head>
<body>
<p> This text is red </p>
</html>
所以,使用这段代码,我的文本实际上是红色的,但是一旦我从代码中删除h1选择器,文本就会恢复为黑色。请问有人可以解释一下为什么会发生这种情况吗?
<body>
。 - Tyler Roper