You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止Prettier自动换行CSS选择器规则?

解决Prettier拆分CSS选择器导致搜索困难的问题

当Prettier将CSS规则的选择器拆分为多行时:

.SectionElementWrap.isDarkBookTheme
  .rootSectionElement:not(.isHighlighted):not(.View-ListDetail)
  .SectElIcon.SectionElement-viewOrPageIcon-white-path
  path {
  fill: rgba(255, 255, 255, 0.87);
}

确实会增加全局搜索这类规则的难度。你提到的html.format.wrapLineLength仅针对HTML,printWidth未解决问题,是因为Prettier对CSS选择器的换行有单独控制项。

  • 在项目的.prettierrc(或其他Prettier配置文件,如.prettierrc.json、prettier.config.js)中添加selectorSeparatorNewline配置,设置为false,即可让同组选择器保持在同一行:
{
  "selectorSeparatorNewline": false
}
  • 若仍有较长选择器被换行,可同时增大printWidth的数值,提升单行可容纳的字符长度阈值,进一步减少不必要的换行。

另外,如果你使用VS Code,需确保编辑器的Prettier配置与项目本地配置一致,避免全局配置覆盖项目设置。

内容的提问来源于stack exchange,提问作者Bardelman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 18:03:17