简体   繁体   English

用于 React 中样式 CSS 的 Visual Studio Code Intellisense?

[英]Visual Studio Code Intellisense for style CSS in React?

Is it possible to get autocomplete or suggestions or intellisense or something for CSS when developing in React?在 React 中开发时,是否可以获得 CSS 的自动完成或建议或智能感知或其他东西?

例子

For example, when I write something like this I want to be able to see all the possibilities for that CSS property.例如,当我写这样的东西时,我希望能够看到 CSS 属性的所有可能性。 I know that I can get this if I use .css files but sometimes I want to use inline CSS for something and it's really annoying that I have to google every time to see what I can use.我知道如果我使用.css文件,我可以得到这个,但有时我想使用内联 CSS 来做一些事情,而且每次我都必须谷歌看看我可以使用什么,这真的很烦人。

Maybe you can use this.也许你可以使用这个。 (Similiar to StyleSheet.create() in React Native): https://github.com/sutanlab/react-styles-hook (类似于 React Native 中的StyleSheet.create() ): https : //github.com/sutanlab/react-styles-hook

I don't think there is some extension that will help you because CSS keeps getting better day by day.我不认为有一些扩展可以帮助你,因为 CSS 每天都在变得更好。 So, the maximum you can achieve is create a cheatsheet and use that for every project.因此,您可以实现的最大目标是创建一个备忘单并将其用于每个项目。

You can install IntelliSense for CSS class names in HTML by Zignd .您可以通过Zignd IntelliSense for CSS class names in HTMLIntelliSense for CSS class names in HTML安装IntelliSense for CSS class names in HTML It is VS Code extension that loads your CSS on program launch and provides autocomplete for that.它是 VS Code 扩展,它在程序启动时加载您的 CSS 并为此提供自动完成功能。

I do not think it is necessary since most of the time, if you are using too many CSS, you are going to have modularity and have external css file.我认为没有必要,因为在大多数情况下,如果您使用太多 CSS,您将具有模块化和外部 css 文件。 But for you, how about temporarily changing "Language Mode" to css.但对你来说,暂时将“语言模式”更改为 css 怎么样。 This may need extra clicks, but it will give you CSS auto-completions or suggestions in Visual Studio Code.这可能需要额外的点击,但它会在 Visual Studio Code 中为您提供 CSS 自动完成或建议。

Open VSCode Settings and search for "css: enabled languages".打开 VSCode 设置并搜索“css:启用的语言”。 Click in the "Edit in settings.json" link and add the following text to the json file:单击“在 settings.json 中编辑”链接并将以下文本添加到 json 文件中:

...
"window.zoomLevel": 2,
"css.enabledLanguages": ["html", "jsx"]

} }

After doing this, press Shift+Ctrl+P and find the command "Cache CSS class definitions".完成此操作后,按 Shift+Ctrl+P 并找到命令“缓存 CSS class 定义”。 This worked for me.这对我有用。 Now I can see Bootstrap classes, for example, inside my jsx code.例如,现在我可以在我的 jsx 代码中看到 Bootstrap 类。

If you are using Styled-Components then try using this Extension:如果您使用的是Styled-Components,请尝试使用此扩展:

Extension Name: vscode-styled-components by Julien Poissonnier扩展名称: vscode-styled-components by Julien Poissonnier

https://marketplace.visualstudio.com/items?itemName=jpoissonnier.vscode-styled-components https://marketplace.visualstudio.com/items?itemName=jpoissonnier.vscode-styled-components

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

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