简体   繁体   中英

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?

例子

For example, when I write something like this I want to be able to see all the possibilities for that CSS property. 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.

Maybe you can use this. (Similiar to StyleSheet.create() in React Native): 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. 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 . It is VS Code extension that loads your CSS on program launch and provides autocomplete for that.

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. But for you, how about temporarily changing "Language Mode" to css. This may need extra clicks, but it will give you CSS auto-completions or suggestions in Visual Studio Code.

Open VSCode Settings and search for "css: enabled languages". Click in the "Edit in settings.json" link and add the following text to the json file:

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

}

After doing this, press Shift+Ctrl+P and find the command "Cache CSS class definitions". This worked for me. Now I can see Bootstrap classes, for example, inside my jsx code.

If you are using Styled-Components then try using this Extension:

Extension Name: vscode-styled-components by Julien Poissonnier

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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