如何移除Atom编辑器代码块的背景色?
Hey there! I’ve dealt with this exact frustration before—when switching built-in themes doesn’t shake that annoying code block background for Go code. Let’s fix it using Atom’s custom styling system, which lets you override any theme’s default rules.
Step 1: Open Atom’s Custom Stylesheet
First, pull up your custom styles file:
- On Windows/Linux: Go to
File > Stylesheet… - On macOS: Go to
Atom > Stylesheet…
This will open thestyles.lessfile—this is where we’ll add our custom rules to nuke the background color.
Step 2: Add the Custom CSS Rule
Paste one of these snippets into the styles.less file, depending on your scenario:
For Go Source Files (.go)
If you’re editing actual Go code files and want to remove the background from code blocks (like function bodies, conditionals, etc.), use this:
// Remove background color for Go code blocks in .go files .editor .syntax--go .syntax--block { background-color: transparent !important; }
The !important flag ensures our rule takes priority over any built-in theme styles that might be forcing the background color.
For Go Code Blocks in Markdown Files
If you’re working with Markdown and want to strip the background from fenced Go code blocks, use this instead:
// Remove background color for Go code blocks in Markdown previews .markdown-preview-view pre.syntax--go { background-color: transparent !important; }
Step 3: Test and Tweak (If Needed)
Save the styles.less file—Atom should automatically apply the changes. If you don’t see a difference immediately, restart Atom to make sure everything loads correctly.
If the above rules don’t work, you can find the exact CSS selector using Atom’s developer tools:
- Open the tools via
View > Developer > Toggle Developer Tools - Use the element picker (the arrow icon in the dev tools toolbar) to click on the code block with the unwanted background
- Look at the CSS classes applied to that element in the "Elements" tab, then adjust your rule in
styles.lessto target those classes specifically.
That should do the trick—no more stubborn code block backgrounds interfering with your Go coding flow!
内容的提问来源于stack exchange,提问作者Blankman

