简体   繁体   English

如何在Chrome开发者工具中查看:: selection

[英]How to see ::selection in Chrome Developer Tools

For some reason, a ::selection declaration in my CSS simply is not working, it is always behaving as per the default (light blue background on Chrome, Mac). 出于某种原因,我的CSS中的::selection声明根本不起作用,它总是按默认行为(Chrome,Mac上的淡蓝色背景)表现。

The code works fine in a jsbin 代码在jsbin中工作正常

::selection {
  background: red;
}

Thus my assumption is something is being overridden somewhere in the project, but I can't find another declaration of ::selection anywhere in the stylesheet. 因此我的假设是在项目的某个地方被覆盖了,但我在样式表中的任何地方都找不到::selection另一个声明。 I was wondering if there is any way to see this in the Developer Tools to try to pinpoint or debug why it isn't working in my project? 我想知道是否有任何方法可以在开发人员工具中看到这一点,试图找出或调试它在我的项目中不起作用的原因?

Even giving the CSS an !important declaration isn't helping. 即使给CSS一个!important声明也无济于事。

edit 编辑

OK, I tried debugging further by adding: 好的,我尝试进一步调试添加:

<style type="text/css">
::selection, ::-moz-selection {
  background: red !important;
}
</style>

to the footer of the document, and thus it turns out that one cannot combine these two declarations in one statement, which was mentioned by Chris Coyier in this comment : 到文档的页脚,因此事实证明,人们不能将这两个声明组合在一个声明中,Chris Coyier在本评论中提到了这一声明

I have a question: Why can´t you put ::selection and ::-moz-selection together and define a value for both of that? 我有一个问题:为什么你不能把:: selection和:: - moz-selection放在一起并为它们定义一个值? If you do that FF will ignore the values. 如果你这样做,FF将忽略这些值。

That's a good CSS lesson! 这是一个很好的CSS课程! When a browser doesn't understand any part of a selector, it ignores the whole selector (even if they are comma separated). 当浏览器不理解选择器的任何部分时,它会忽略整个选择器(即使它们以逗号分隔)。 There are some exceptions but mostly in old browsers (IE 7?). 有一些例外但主要是旧浏览器(IE 7?)。

So all is well and working again, but the question still stands I suppose, is there a way to see this declaration in the devtools somehow? 所以一切都很好并再次工作,但问题仍然存在,我想,有没有办法在某种程度上看到devtools中的这个声明?

edit 2 编辑2

Ok, of course, when the declaration sits on its own line, then it appears in the inspector. 好吧,当然,当声明位于自己的行上时,它会出现在检查器中。

edit 3 编辑3

A very relevant SO question: Why isn't it possible to combine vendor-specific pseudo-elements/classes into one rule set? 一个非常相关的SO问题: 为什么不能将特定于供应商的伪元素/类组合成一个规则集?

I'm just surprised Chrome doesn't just still show the malformed declaration in the inspector rather than hiding it completely. 我只是感到惊讶Chrome不仅仅在检查员中显示格式错误的声明而不是完全隐藏它。

Try to check via inspect element. 尝试通过inspect元素检查。

  1. Right click on web page 右键单击网页
  2. Select "inspect" option 选择“检查”选项
  3. In inspect element panel, there will be style appear in right hand side. 在检查元件面板中,右侧会出现样式。
  4. You will find your :selection declaration in it. 你会在其中找到你的:选择声明。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM