<\/code>或根元素加上.theme-dark<\/code>類,整個頁面的樣式就會自動跟著變。<\/p>

在組件中使用變量<\/h3>

定義好變量之後,就可以在任意CSS 規(guī)則中使用它們: <\/p>\"How

 .button {\n  background-color: var(--color-primary);\n  color: var(--color-text);\n}<\/pre>

這樣做的好處是,無論當前是什麼主題,按鈕都會自動適配對應的顏色<\/strong>,不需要為每個主題單獨寫樣式。<\/p>

你也可以嵌套使用變量,比如設置一個默認值:<\/p>

 background-color: var(--custom-bg, var(--color-bg));<\/pre>

這表示如果--custom-bg<\/code>沒有定義,就用--color-bg<\/code>替代。<\/p>


動態(tài)切換主題的方法<\/h3>

要讓主題可以切換,一般需要一點JavaScript 來操作類名或者數(shù)據(jù)屬性。例如:<\/p>

 <fieldset id="yus0u"><samp id="yus0u"></samp></fieldset><fieldset id="yus0u"><samp id="yus0u"></samp></fieldset>
    • <center id="yus0u"></center>
      <option id="yus0u"><strong id="yus0u"></strong></option>