我的样式表没有覆盖Normalize.css边距

我的样式表没有覆盖Normalize.css边距,css,Css,我不明白为什么我的样式表没有覆盖normalize.css的边距值 在html中,样式表链接的顺序是正确的: <link rel="stylesheet" href="css/normalize.css"> <link rel="stylesheet" href="css/2may.css"> 通过我的样式表,我试图覆盖这一点: *{ box-sizing: border-box; color: #ddd; padding: 0; border: 0;

我不明白为什么我的样式表没有覆盖normalize.css的边距值

在html中,样式表链接的顺序是正确的:

<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/2may.css">
通过我的样式表,我试图覆盖这一点:

*{
  box-sizing: border-box;
  color: #ddd;
  padding: 0; 
  border: 0;
  margin: 0; 
  text-decoration: none;
}
因为h1比*

你应该读书

示例:

*               /* a=0 b=0 c=0 -> specificity =   0 */
LI              /* a=0 b=0 c=1 -> specificity =   1 */
UL LI           /* a=0 b=0 c=2 -> specificity =   2 */
UL OL+LI        /* a=0 b=0 c=3 -> specificity =   3 */
H1 + *[REL=up]  /* a=0 b=1 c=1 -> specificity =  11 */
UL OL LI.red    /* a=0 b=1 c=3 -> specificity =  13 */
LI.red.level    /* a=0 b=2 c=1 -> specificity =  21 */
#x34y           /* a=1 b=0 c=0 -> specificity = 100 */
#s12:not(FOO)   /* a=1 b=0 c=1 -> specificity = 101 */
在您的情况下,只需添加:

margin: 0;

添加到h1声明。

如果要覆盖normalize.css中的h1样式,可能需要在css中以相同的选择器为目标:

h1 {
  box-sizing: border-box;
  color: #ddd;
  padding: 0; 
  border: 0; 
  margin: 0;  /* this is the new one */
  text-decoration: none;
}

更具体的规则会覆盖像*这样的一般规则。这就是normalize.css覆盖该选择器的原因

例如,如果我有这两个选择器,则应用更具体的一个,在本例中,它是.foosomeId:

鉴于,如果我有两个相同的文件,则第一个文件适用:

.foo{ color: red } //text will be red

.foo{ color: blue }
以下是有关详细信息的规范链接:

这是因为h1选择器具有比**{}更高的指定性。我相信,如果给元素一个样式,它不会覆盖任何内容。
.foo#someId { 
  color: red; 
}

.foo { color: blue; }
.foo{ color: red } //text will be red

.foo{ color: blue }