大纲:none VS 大纲:0

outline: none VS outline: 0

我正在阅读 this question on disabling the dashed borders around <a> links. Some answers used outline: none, while some 使用 outline: 0

使用outline: noneoutline: 0有什么区别吗?

根据MDN

The CSS outline property is a shorthand property for setting one or more of the individual outline properties outline-style, outline-width and outline-color in a single declaration

所以当你将outline设置为none0时,你实际上是在告诉浏览器设置3个属性(outline-styleoutline-widthoutline-color)

我使用 Firefox Developer Tools 来找出区别:

如您所见,它们都使用默认文本颜色作为 outline-color,并且它们都将 outline-style 设置为 none。唯一的区别是 outline-width:

  • outline0时,outline-width0px
  • outlinenone时,outline-widthmedium

这是两者之间的唯一区别。您可以使用任何一个,它们都将以相同的方式显示(因为 outline-stylenone,轮廓的宽度无关紧要)。