自訂顏色和主題的Bulma
P粉757640504
P粉757640504 2024-03-28 12:54:26
0
1
437

我目前正在嘗試以 bulma 為基礎做一個多主題設計系統。 但我目前正在努力添加多主題系統。

我將其添加到我的 customstyle scss 檔案中,但它似乎不起作用

@charset "utf-8";


:root {
    --primary: red;
    --secondary: #068295;
}

body[class="light"] {
    --primary: #F7A800;
    --secondary: #068295;
}

body[class="dark"] {
    --primary: blue;
    --secondary: #068295;
}

$primary: var(--primary); // this works 
$background: blue;
$text-strong: red;

$secondary: #8BC91D; // this works but without theming
// $secondary: var(--secondary); // this doesn't work 
$secondary-invert: findColorInvert($secondary) !default;

$custom-colors: (
    "secondary":($secondary, $secondary-invert),
);

@import "../node_modules/bulma/sass/utilities/_all.sass";
@import "../node_modules/bulma/sass/base/_all.sass";
@import "../node_modules/bulma/sass/elements/button.sass";

當我執行node sass指令產生css檔時 我可以看到當我不使用變數時產生的 is-secondary 屬性,但是當我使用變數來定義我的 $secondary 變數時,不會產生 is-secondary 屬性

P粉757640504
P粉757640504

全部回覆(1)
P粉745412116

Bulma 目前的主版本不支援 css 變數。

我透過使用 css-variables 分支使其工作。 npm 我 https://github.com/jgthms/bulma/tree/bulma-v1-css-variables;

先進行導入:

@import 'bulma/sass/utilities/_all';
@import 'bulma/sass/base/_all';
@import 'bulma/sass/elements/_all';
@import 'bulma/sass/form/_all';
@import 'bulma/sass/components/_all';
@import 'bulma/sass/grid/_all';
@import 'bulma/sass/helpers/_all';
@import 'bulma/sass/layout/_all';
@import 'bulma/sass/themes/default.scss';

themes/default.scss 使所有 css 變數基於 sass 變數。

之後你可以使用 CSS 變數來修改預設值,這樣你就可以擁有黑暗模式、主題切換器和其他東西。

:root {
  --bulma-danger-h: 190;
}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!