理解 CSS Lint 警告
我正在为我们的网站编写 CSS,并且刚刚通过 CSS Lint 运行它。我正在努力理解相当多的警告,因此非常需要社区的帮助。
不要在选择器中使用 ID。
这不是 ID 的重点吗?用于寻址页面上的特定元素?
选择器中有 2 个 ID,真的吗?
有没有比在同一行中使用两个选择器更好的方法来选择元素?
破盒子模型:使用高度和边框顶部。
我不知道这意味着什么。我的理解是盒子高度与边框高度是分开的。我已经为元素定义了一个高度,然后单独定义了边框边,我哪里出错了?
标题 (h1) 不应被限定。
I am writing the CSS for our website and I just ran it through CSS Lint. I'm struggling making sense of quite a few of the warnings so would greatly the community's assistance.
Don't use IDs in selectors.
Isn't that the point of the IDs? To be used to address a particular element on the page?
2 IDs in the selector, really?
Is there a better way of selecting an element rather than using two selectors in the same line?
Broken box model: using height with border-top.
I have no idea what this means. My understanding is that box height is separate to border height. I have defined a height for the element than then the border sides are being individually defined, where am I going wrong?
Heading (h1) should not be qualified.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有使用过 CSS Lint,所以我不确定其中的大部分内容。但关于 2.“选择器中的 2 个 ID”,我猜他们正在标记它,因为它可能是多余的。 ID 选择器指示该元素在页面上是唯一的。因此,如果您在选择器中使用两个 ID,例如
#main #navigation
,您可能也可以轻松使用最后一个 ID,例如#navigation
。但是,如果您使用较高的 ID 来指示您所在的页面类型,那么对我来说看起来不错。
有很多善意的 CSS 人员非常热衷于告诉你应该做什么和不应该做什么,无论你想做什么。
I haven’t used CSS Lint, so I’m not sure about most of these. But regarding 2., “2 IDs in the selector”, I guess they’re flagging it because it’s likely to be redundant. An ID selector indicates that the element is unique on the page. So if you’re using two IDs in the selector, e.g.
#main #navigation
, you could probably just as easily use the last one, e.g.#navigation
.However, if you’re using the higher ID to e.g. indicate what kind of page you’re on, that looks fine to me.
There are quite a lot of well-intentioned CSS folks who are very keen to tell you what you should and shouldn’t do, regardless of what you’re trying to do.
如果您浏览 http://csslint.net/about.html,它会显示以下内容:
我认为 ID 的创建是有原因的,如果你计算正确,你就不需要担心破盒子模型。
If you go through http://csslint.net/about.html, it says the following:
I think IDs were made for a reason, and if you do the calculations right, you dont need to worry about the broken box model.