樣式編輯器

翻譯不完整。 請幫助我們翻譯這篇文章!

樣式編輯器使您能夠:

  • 查看和編輯與頁面關聯的所有樣式表
  • 從頭開始創建新樣式表並將其應用於該頁面
  • 導入現成的樣式表並將其應用於該頁面

要打開樣式編輯器,請從“ 網頁開發者”選單中選擇“樣式編輯器”選項。(這是Mac上“工具”選單中的子選單)。 工具箱將會顯示在瀏覽器的視窗底部,並顯示樣式編輯器:

樣式編輯器分為兩個主要部分:

從Firefox 33開始,樣式編輯器還有第三個組件: 媒體測攔

樣式列表

左側的樣式列表格列出了當前頁面正在使用的所有樣式表。 通過單擊工作表名稱左側的眼球圖標,可以快速打開和關閉樣式表的使用。 通過單擊列表中每個樣式表選項右下角的“儲存”按鈕,可以將對樣式表所做的任何更改保存到電腦硬碟裡。

樣式編輯器

中間是編輯器窗格。 您可以在此處閱讀和編輯所選樣式表的原始碼。 您所做的任何更改都會立即應用於頁面。 這使得嘗試,修改和測試更改變得容易。 對更改感到滿意後,可以單擊樣式列表窗格中工作表條目上的“儲存”按鈕,以在電腦上儲存副本。

The editor provides line numbers and syntax highlighting to help make it easier to read your CSS. It also supports a number of keyboard shortcuts.

The Style Editor automatically de-minimizes style sheets that it detects, without affecting the original. This makes it much easier to work on pages that have been optimized.

The Style Editor supports autocomplete. Just start typing, and it will offer you a list of suggestions.

You can switch autocomplete off in the Style Editor settings.

The media sidebar

From Firefox 33 onwards, the Style Editor displays a sidebar on the right-hand side whenever the current sheet contains any @media rules. The sidebar lists the rules and provides a link to the line of the sheet where the rule is defined. Click an item to jump to that rule in the sheet. The condition text of the rule is greyed-out if the media query doesn’t currently apply.

The media sidebar works especially well with Responsive Design View for creating and debugging responsive layouts:

Creating and importing style sheets

You can create a new style sheet by clicking the New button in the toolbar. Then you can just start entering CSS into the new editor and watch as the new styles apply in real time just like changes to the other sheets.

You can load a style sheet from disk and apply it to the page by clicking the Import button.

Source map support

Web developers often create CSS files using a preprocessor like Sass, Less, or Stylus. These tools generate CSS files from a richer and more expressive syntax. If you do this, being able to see and edit the generated CSS is not so useful, because the code you maintain is the preprocessor syntax, not the generated CSS. So you'd need to edit the generated CSS, then manually work out how to reapply that to the original source.

Source maps enable the tools to map back from the generated CSS to the original syntax, so they can display, and allow you to edit, files in the original syntax. From Firefox 29 onwards, the Style Editor can understand CSS source maps.

This means that if you use, for example, Sass, then the Style Editor will show you, and allow you to edit, Sass files, rather than the CSS that is generated from them:

For this to work, you must:

  • use a CSS preprocessor that understands the Source Map Revision 3 proposal. Currently this means Sass 3.3.0 or above or the 1.5.0 version of Less. Other preprocessors are actively working on adding support, or considering it.
  • actually instruct the preprocessor to generate a source map, for example by passing the --sourcemap argument to the Sass command-line tool

Viewing original sources

Now, if you check "Show original sources" in the Style Editor settings, the links next to CSS rules in the Rules view will link to the original sources in the Style Editor.

From Firefox 35 onwards original sources are displayed by default.

Editing original sources

You can also edit the original sources in the Style Editor and see the results applied to the page immediately. To get this to work there are two extra steps.

First, set up your preprocessor so it watches the original source and automatically regenerates the CSS when the source changes. With Sass you can do this simply by passing the --watch option:

sass index.scss:index.css --sourcemap --watch

Next, save the original source in the Style Editor by clicking the "Save" button next to the file, and saving it over the original file.

Now when you make changes to the source file in the Style Editor the CSS is regenerated and you can see the changes right away.

Keyboard shortcuts

Source editor shortcuts

This table lists the default shortcuts for the source editor.

In the Editor Preferences section of the developer tools settings, you can choose to use Vim, Emacs, or Sublime Text key bindings instead.

To select these, visit about:config, select the setting devtools.editor.keymap, and assign "vim" or "emacs", or "sublime" to that setting. If you do this, the selected bindings will be used for all the developer tools that use the source editor. You need to reopen the editor for the change to take effect.

From Firefox 33 onwards, the key binding preference is exposed in the Editor Preferences section of the developer tools settings, and you can set it there instead of about:config.

Command Windows macOS Linux
Go to line Ctrl + J, Ctrl + G Cmd + J, Cmd + G Ctrl + J, Ctrl + G
Find in file Ctrl + F Cmd + F Ctrl + F
Select all Ctrl + A Cmd + A Ctrl + A
Cut Ctrl + X Cmd + X Ctrl + X
Copy Ctrl + C Cmd + C Ctrl + C
Paste Ctrl + V Cmd + V Ctrl + V
Undo Ctrl + Z Cmd + Z Ctrl + Z
Redo Ctrl + Shift + Z / Ctrl + Y Cmd + Shift + Z / Cmd + Y Ctrl + Shift + Z / Ctrl + Y
Indent Tab Tab Tab
Unindent Shift + Tab Shift + Tab Shift + Tab
Move line(s) up Alt + Up Alt + Up Alt + Up
Move line(s) down Alt + Down Alt + Down Alt + Down
Comment/uncomment line(s) Ctrl + / Cmd + / Ctrl + /