简体   繁体   English

在Chrome开发者工具中添加新的CSS规则,而不是通过检查元素?

[英]Add a new CSS rule in Chrome Developer Tools, not via inspecting an element?

I want to add a new style rule directly in the Chrome developer tools, but I'm struggling to do so, from following the guide at https://developers.google.com/chrome-developer-tools/docs/elements-styles#styles_edit 我想直接在Chrome开发者工具中添加新的样式规则,但我很难按照https://developers.google.com/chrome-developer-tools/docs/elements-styles中的指南进行操作#styles_edit

This is the CSS rule I want to add - I can't set up the selector by selecting an element, I need to type it it directly. 这是我要添加的CSS规则 - 我无法通过选择元素来设置选择器,我需要直接输入它。 I want to do this to make sure that the CSS syntax itself is correct. 我想这样做是为了确保CSS语法本身是正确的。

.y-axis .tick:nth-child(2):nth-last-child(1) text {
  font-weight: bold;
}

I have clicked on the "plus" sign to add the rule, but when I do, I'm finding that the developer tools just won't let me add it by typing or pasting it in - it either goes gray, or it pastes in like this, with the brackets wrong: 我点击了“加号”标志来添加规则,但是当我这样做时,我发现开发人员工具不会让我通过输入或粘贴它来添加它 - 它要么变灰,要么粘贴像这样,括号错误:

在此输入图像描述

Then when I press Enter or tab out, or try to edit the rule, the text just vanishes. 然后,当我按Enter或Tab键,或尝试编辑规则时,文本就会消失。 Very frustrating. 很沮丧。

How can I add new CSS rules in the developer tools that aren't amenable to being set up via inspecting an element? 如何在开发人员工具中添加新的CSS规则,这些规则不适合通过检查元素进行设置?

Apologies if this is the wrong forum for this question. 如果这是这个问题的错误论坛,请道歉。

For it not to go gray, you need to select an element to which the rules DOES apply. 为了不变灰,您需要选择规则适用的元素。

You are not showing your code, but that rule will only apply to a second child of .tick which is ALSO the last child. 您没有显示您的代码,但该规则仅适用于.tick的第二个孩子,它也是最后一个孩子。 If the element you clicked to create that rule does NOT meet those selectors, it will go gray, and BELOW the other rules for the element itself. 如果您单击以创建该规则的元素不符合这些选择器,则它将变为灰色,并且低于元素本身的其他规则。

Current versions of Chrome will won't move it or hide it until you select another element, so this is probably an old issue, but for others experiencing similar issues: "The rule must apply to the selected element". 当前版本的Chrome将不会移动它或隐藏它,直到您选择另一个元素,因此这可能是一个老问题,但对于遇到类似问题的其他人:“规则必须适用于所选元素”。 But since you can't touch the pseudo element until you add content:"" to it, you'll have to create the rule, add content property to it, then touch the pseudo element, and then it will not be dimmed anymore. 但是,因为在添加内容之前你不能触摸伪元素:“”它,你必须创建规则,向它添加内容属性,然后触摸伪元素,然后它将不再变暗。

Again, current Chrome allows you edit it even when dimmed. 同样,当前的Chrome允许您即使在变暗时也可以对其进行编辑。

First, select some element and add a new CSS rule as described in the Chrome documentation : 首先,选择一些元素并添加新的CSS规则,如Chrome文档中所述

Click the New Style Rule 单击“ 新建样式规则” 新风格规则 icon located in the upper-right corner of the styles editor. 图标位于样式编辑器的右上角。 A new rule with an automatically suggested selector appears. 出现带有自动建议选择器的新规则。

Then, click the inspector-stylesheet:1 link in the top-right corner of the newly added rule box and edit the rule in the Sources tab of the Developer Tools. 然后,单击新添加的规则框右上角的inspector-stylesheet:1链接,并在Developer Tools的Sources选项卡中编辑规则。

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

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