简体   繁体   English

Visual Studio Code 和 emmet !important CSS 修饰符

[英]Visual Studio Code and emmet !important CSS modifier

I have problems with the use of !我在使用时遇到问题! in my CSS code.在我的 CSS 代码中。

If I take the example in the Emmet documentation :如果我以 Emmet 文档中的示例为例:

p!+m10e!

Should produce:应该产生:

padding:  !important;
margin: 10em !important;

On my side, it doesn't work.在我这边,它不起作用。 p!+m10e works, but p!+m10e! p!+m10e有效,但是p!+m10e! does not.才不是。 The final exclamation point seems to be a problem.最后一个感叹号好像有问题。

I did another test with dn!我用dn!做了另一个测试dn! to display display: none !important;显示display: none !important; , the problem is the same. ,问题是一样的。

在此处输入图片说明

Do you have an idea?你有想法吗?

Enabling Trigger Expansion on Tab seems to have solved the problem on my machine. Trigger Expansion on Tab启用Trigger Expansion on Tab似乎解决了我机器上的问题。 在此处输入图片说明

The solution lies in disabling text-suggestions .解决方案在于禁用text-suggestions In fact, I think the fact that IntelliSense shows the !important and !default when you type an exclamation mark, makes Emmet mess up.事实上,我认为 IntelliSense 在您键入感叹号时显示!important!default的事实让 Emmet 搞砸了。

So I disabled this:所以我禁用了这个:

"editor.suggest.showWords": false

If you prefer the UI, you can also find it by doing the following:如果您更喜欢 UI,也可以通过执行以下操作来找到它:

  1. Navigate the menus: click on - File > Preferences > Settings (or press Ctrl + ,)导航菜单:单击 - 文件 > 首选项 > 设置(或按 Ctrl + ,)

  2. Type Show Words in the search box at the top在顶部的搜索框中键入 Show Words

  3. Uncheck the setting Editor > Suggest: Show Words取消选中设置 Editor > Suggest: Show Words

What about creating your own snippet?创建自己的片段怎么样?

Open Visual Studio Code --> Press ctrl+shift+P --> Search for "Preferences: Configure User Snippets" --> Select "css.json" --> Add the code打开 Visual Studio Code --> 按 ctrl+shift+P --> 搜索“首选项:配置用户片段” --> 选择“css.json” --> 添加代码

片段

现场演示

A few observations, this may help future readers:一些观察,这可能对未来的读者有所帮助:

  • CTRL + Space forces the non-suggested(intellisense) expansion. CTRL + Space强制非建议(智能感知)扩展。

  • "emmet.triggerExpansionOnTab": true also expands non-suggested option. "emmet.triggerExpansionOnTab": true也扩展非建议选项。

  • If you type dn!i it will give you suggestion dn: i !important;如果你输入dn!i它会给你建议dn: i !important; then you delete 'i' then hit enter/tab, it expands as expected.然后你删除 'i' 然后按 Enter/tab,它会按预期扩展。 在此处输入图片说明

  • I think the bug https://github.com/microsoft/vscode/issues/120245 still hasn't been resolved completely.我认为错误https://github.com/microsoft/vscode/issues/120245仍然没有完全解决。 Otherwise you could've typed 'dn!important` and it would've expanded as expected.否则,您可以输入“dn!important”,它会按预期扩展。

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

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