【css】vscode自动格式化
warning:
这篇文章距离上次修改已过442天,其中的内容可能已经有所变动。
VSCode自带格式化功能,可以通过快捷键或者在设置中配置自动保存来实现。
快捷键格式化:
- 在Windows/Linux上,使用
Shift + Alt + F或者在设置中搜索format找到editor.formatOnType并启用。 - 在macOS上,使用
Cmd + Shift + F或者在设置中搜索format找到editor.formatOnType并启用。
- 在Windows/Linux上,使用
开启自动保存:
- 打开设置(
File > Preferences > Settings或Code > Preferences > Settings)。 - 在搜索框中输入
auto save。 - 选择
editor.formatOnSave并启用。
- 打开设置(
如果你想要在保存文件时自动格式化CSS,可以在VSCode的设置中添加以下配置:
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
}
}这样,每次保存文件时,VSCode都会自动应用格式化和代码修复。如果你使用的是CSS预处理器如SCSS或LESS,确保你安装了相应的扩展,如Sass 或 LESS,这样VSCode才能识别文件格式并进行格式化。
评论已关闭